<commit_before>class ViewModel

  #@@@@@@@@@@@@@@
  # Class methods

  _nextId = 1
  @nextId = -> _nextId++
  @persist = true

  # These are view model properties the user can use
  # but they have special meaning to ViewModel
  @properties =
    autorun: 1
    events: 1
    share: 1
    mixin: 1
    ref: 1
    load: 1
    onRendered: 1
    onCreated: 1
    onDestroyed: 1

  # The user can't use these properties
  # when defining a view model
  @reserved =
    vmId: 1
    vmHashCache: 1
    vmPathToParent: 1
    templateInstance: 1
    parent: 1
    children: 1
    reset: 1
    data: 1


  # These are objects used as bindings but do not have
  # an implementation
  @nonBindings =
    throttle: 1
    optionsText: 1
    optionsValue: 1
    defaultText: 1
    defaultValue: 1

  @bindObjects = {}

  @byId = {}
  @byTemplate = {}
  @add = (viewmodel) ->
    ViewModel.byId[viewmodel.vmId] = viewmodel
    templateName = ViewModel.templateName(viewmodel.templateInstance)
    if templateName
      if not ViewModel.byTemplate[templateName]
        ViewModel.byTemplate[templateName] = {}
      ViewModel.byTemplate[templateName][viewmodel.vmId] = viewmodel

  @remove = (viewmodel) ->
    delete ViewModel.byId[viewmodel.vmId]
    templateName = ViewModel.templateName(viewmodel.templateInstance)
    if templateName
      delete ViewModel.byTemplate[templateName][viewmodel.byId]

  @find = (templateNameOrPredicate, predicateOrNothing) ->
    templateName = _.isString(templateNameOrPredicate) and templateNameOrPredicate
    predicate = if templateName then predicateOrNothing else _.isFunction(templateNameOrPredicate) and templateNameOrPredicate

    vmCollection = if templateName then ViewModel.byTemplate[templateName] else ViewModel.byId
    vmCollectionValues = _.values(vmCollection)
    if predicate
      return _.filter(vmCollection, predicate)
    else
      return vmCollectionValues

  @findOne = (templateNameOrPredicate, predicateOrNothing) ->
    return _.first ViewModel.find( templateNameOrPredicate, predicateOrNothing )

  @check = (key, args...) ->
    if Meteor.isDev and not ViewModel.ignoreErrors
      Package['manuel:viewmodel-debug']?.VmCheck key, args...
    return

  @onCreated = (template, initial) ->
    return ->
      templateInstance = this
      initial = initial(templateInstance.data) if _.isFunction(initial)
      currentDataAutorunSet = false<commit_msg>fix for bug in @remove<commit_after>class ViewModel

  #@@@@@@@@@@@@@@
  # Class methods

  _nextId = 1
  @nextId = -> _nextId++
  @persist = true

  # These are view model properties the user can use
  # but they have special meaning to ViewModel
  @properties =
    autorun: 1
    events: 1
    share: 1
    mixin: 1
    ref: 1
    load: 1
    onRendered: 1
    onCreated: 1
    onDestroyed: 1

  # The user can't use these properties
  # when defining a view model
  @reserved =
    vmId: 1
    vmHashCache: 1
    vmPathToParent: 1
    templateInstance: 1
    parent: 1
    children: 1
    reset: 1
    data: 1


  # These are objects used as bindings but do not have
  # an implementation
  @nonBindings =
    throttle: 1
    optionsText: 1
    optionsValue: 1
    defaultText: 1
    defaultValue: 1

  @bindObjects = {}

  @byId = {}
  @byTemplate = {}
  @add = (viewmodel) ->
    ViewModel.byId[viewmodel.vmId] = viewmodel
    templateName = ViewModel.templateName(viewmodel.templateInstance)
    if templateName
      if not ViewModel.byTemplate[templateName]
        ViewModel.byTemplate[templateName] = {}
      ViewModel.byTemplate[templateName][viewmodel.vmId] = viewmodel

  @remove = (viewmodel) ->
    delete ViewModel.byId[viewmodel.vmId]
    templateName = ViewModel.templateName(viewmodel.templateInstance)
    if templateName
      delete ViewModel.byTemplate[templateName][viewmodel.vmId]

  @find = (templateNameOrPredicate, predicateOrNothing) ->
    templateName = _.isString(templateNameOrPredicate) and templateNameOrPredicate
    predicate = if templateName then predicateOrNothing else _.isFunction(templateNameOrPredicate) and templateNameOrPredicate

    vmCollection = if templateName then ViewModel.byTemplate[templateName] else ViewModel.byId
    vmCollectionValues = _.values(vmCollection)
    if predicate
      return _.filter(vmCollection, predicate)
    else
      return vmCollectionValues

  @findOne = (templateNameOrPredicate, predicateOrNothing) ->
    return _.first ViewModel.find( templateNameOrPredicate, predicateOrNothing )

  @check = (key, args...) ->
    if Meteor.isDev and not ViewModel.ignoreErrors
      Package['manuel:viewmodel-debug']?.VmCheck key, args...
    return

  @onCreated = (template, initial) ->
    return ->
      templateInstance = this
      initial = initial(templateInstance.data) if _.isFunction(initial)
      currentDataAutorunSet = false
{'fraction_non_alphanumeric': 0.08732628085459448, 'fraction_numerical': 0.009541588881974695, 'mean_word_length': 3.3559168925022584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3352819', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1403, 'n_words': 379}