<commit_before>{Serenade} = require './serenade'
{Collection} = require './collection'
{AssociationCollection} = require './association_collection'
{Events} = require './events'
{pairToObject, serializeObject, extend, get} = require './helpers'

prefix = "_prop_"
exp = /^_prop_/
define = Object.defineProperties # we check for the plural because it is unsupported in buggy IE8

addGlobalDependencies = (object, dependency, names) ->
  unless object["_glb_" + dependency]
    object["_glb_" + dependency] = true
    for name in names
      if name.match(/\./)
        type = "singular"
        [name, subname] = name.split(".")
      else if name.match(/:/)
        type = "collection"
        [name, subname] = name.split(":")
      Serenade.globalDependencies[subname] or= []
      Serenade.globalDependencies[subname].push({ object, dependency, subname, name, type })

addDependencies = (object, dependency, names) ->
  names = [].concat(names)
  for name in names
    [name, subname] = name.split(/[:\.]/) if name.match(/[:\.]/)
    object["_dep_" + name] ||= []
    object["_dep_" + name].push(dependency) if object["_dep_" + name].indexOf(dependency) is -1

triggerGlobal = (object, names) ->
  for name in names
    if Serenade.globalDependencies[name]
      for dependency in Serenade.globalDependencies[name]
        if dependency.type is "singular"
          if object is dependency.object.get(dependency.name)
            triggerChangesTo(dependency.object, [dependency.dependency])
        else if dependency.type is "collection"
          if object in dependency.object.get(dependency.name)
            triggerChangesTo(dependency.object, [dependency.dependency])<commit_msg>Don't add global dependencies when it's not necessary<commit_after>{Serenade} = require './serenade'
{Collection} = require './collection'
{AssociationCollection} = require './association_collection'
{Events} = require './events'
{pairToObject, serializeObject, extend, get} = require './helpers'

prefix = "_prop_"
exp = /^_prop_/
define = Object.defineProperties # we check for the plural because it is unsupported in buggy IE8

addGlobalDependencies = (object, dependency, names) ->
  unless object["_glb_" + dependency]
    object["_glb_" + dependency] = true
    for name in names
      if name.match(/\./)
        type = "singular"
        [name, subname] = name.split(".")
      else if name.match(/:/)
        type = "collection"
        [name, subname] = name.split(":")

      if subname
        Serenade.globalDependencies[subname] or= []
        Serenade.globalDependencies[subname].push({ object, dependency, subname, name, type })

addDependencies = (object, dependency, names) ->
  names = [].concat(names)
  for name in names
    [name, subname] = name.split(/[:\.]/) if name.match(/[:\.]/)
    object["_dep_" + name] ||= []
    object["_dep_" + name].push(dependency) if object["_dep_" + name].indexOf(dependency) is -1

triggerGlobal = (object, names) ->
  for name in names
    if Serenade.globalDependencies[name]
      for dependency in Serenade.globalDependencies[name]
        if dependency.type is "singular"
          if object is dependency.object.get(dependency.name)
            triggerChangesTo(dependency.object, [dependency.dependency])
        else if dependency.type is "collection"
          if object in dependency.object.get(dependency.name)
            triggerChangesTo(dependency.object, [dependency.dependency])
{'fraction_non_alphanumeric': 0.13554392088423503, 'fraction_numerical': 0.0011634671320535194, 'mean_word_length': 3.4374193548387098, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, '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': '2320114', 'n_tokens_mistral': 1024, 'n_tokens_neox': 970, 'n_words': 270}