<commit_before>Foundation = require 'art-foundation'
{BaseObject, timeout, inspect} = Foundation

module.exports = class ElementFactory extends BaseObject
  @singletonClass()

  @newElement: (elementClassName, props, children) => @singleton.newElement elementClassName, props, children

  constructor: ->
    super
    @_elementClassesByName = {}

  register: (klass) ->
    name = klass.name
    if @_elementClassesByName[name]
      timeout 100, => # timeout so namespacePath is updated
        console.warn "ElementFactory: element with class-name #{name} already exists. ClassPaths: Existing: #{@_elementClassesByName[name].namespacePath}, Adding: #{klass.namespacePath}"
    else
      @_elementClassesByName[name] = klass

  classForElement: (elementClassName) -> @_elementClassesByName[elementClassName]

  newElement: (elementClassName, props, children) ->
    klass = @_elementClassesByName[elementClassName]
    throw new Error "ElementFactor: class not found for #{inspect elementClassName} (props: #{inspect props})" unless klass
    new @_elementClassesByName[elementClassName] props, children<commit_msg>NEW: ElementFactory.elementClasses provides a global list of registered elementClasses<commit_after>Foundation = require 'art-foundation'
{BaseObject, timeout, inspect} = Foundation

module.exports = class ElementFactory extends BaseObject
  @singletonClass()

  @newElement: (elementClassName, props, children) => @singleton.newElement elementClassName, props, children

  constructor: ->
    super
    @_elementClasses = {}

  @classGetter
    elementClasses: -> @singleton._elementClasses

  register: (klass) ->
    name = klass.name
    if @_elementClasses[name]
      timeout 100, => # timeout so namespacePath is updated
        console.warn "ElementFactory: element with class-name #{name} already exists. ClassPaths: Existing: #{@_elementClasses[name].namespacePath}, Adding: #{klass.namespacePath}"
    else
      @_elementClasses[name] = klass

  classForElement: (elementClassName) -> @_elementClasses[elementClassName]

  newElement: (elementClassName, props, children) ->
    klass = @_elementClasses[elementClassName]
    throw new Error "ElementFactor: class not found for #{inspect elementClassName} (props: #{inspect props})" unless klass
    new @_elementClasses[elementClassName] props, children
{'fraction_non_alphanumeric': 0.10030004286326619, 'fraction_numerical': 0.002571795970852979, 'mean_word_length': 5.158311345646438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357541', 'n_tokens_mistral': 610, 'n_tokens_neox': 610, 'n_words': 172}