<commit_before>$.extend true, window, 
  SlickBone: {}

class SlickBone.Collection extends Backbone.Collection
  setGrid: (@grid) ->
    @_setGridData()
    
    @grid.onCellChange.subscribe (event, args) =>
      modelToUpdate = if args.item.id? then @get(args.item.id) else @getByCid(args.item.cid)
      modelToUpdate.set(args.item)
    
    @grid.onAddNewRow.subscribe (event, args) => @add(args.item)

    @bind 'add', (model)  => 
      @grid.updateRowCount()
      @grid.invalidateRow(@length - 1)
      @grid.render()

    @bind 'change', (model) =>
      @grid.invalidateRow @indexOf(model)
      @grid.render()
    
    @bind 'remove', (model) => 
      @grid.updateRowCount()
      @grid.render()
      
    @bind 'refresh', (model) => @_setGridData()
      
  _setGridData: ->
    @grid.setData @
    @grid.invalidate()
  
  getItem: (index) -> 
    model = @at(index)
    if model?
      attrs = model.toJSON()
      attrs.cid = model.cid
    attrs

class SlickBone.Model extends Backbone.Model
  initialize: ->
    @bind 'change', => @deriveFields()

  @derivedField: (fieldName, derivationFunction) ->
    @_derivations ||= []
    @_derivations.push
      field: fieldName
      func:  derivationFunction

  @prependDerivedField: (fieldName, derivationFunction) ->
    @_derivations ||= []
    @_derivations.unshift
      field: fieldName
      func: derivationFunction
  
  deriveFields: ->
    for derivation in @constructor._derivations
      result = {}
      result[derivation.field] = derivation.func(@)
      @set(result, silent: true)<commit_msg>Derived fields now are inheritable, not shared amongst entire inheritance chain.<commit_after>$.extend true, window, 
  SlickBone: {}

class SlickBone.Collection extends Backbone.Collection
  setGrid: (@grid) ->
    @_setGridData()
    
    @grid.onCellChange.subscribe (event, args) =>
      modelToUpdate = if args.item.id? then @get(args.item.id) else @getByCid(args.item.cid)
      modelToUpdate.set(args.item)
    
    @grid.onAddNewRow.subscribe (event, args) => @add(args.item)

    @bind 'add', (model)  => 
      @grid.updateRowCount()
      @grid.invalidateRow(@length - 1)
      @grid.render()

    @bind 'change', (model) =>
      @grid.invalidateRow @indexOf(model)
      @grid.render()
    
    @bind 'remove', (model) => 
      @grid.updateRowCount()
      @grid.render()
      
    @bind 'refresh', (model) => @_setGridData()
      
  _setGridData: ->
    @grid.setData @
    @grid.invalidate()
  
  getItem: (index) -> 
    model = @at(index)
    if model?
      attrs = model.toJSON()
      attrs.cid = model.cid
    attrs

class SlickBone.Model extends Backbone.Model
  initialize: ->
    @bind 'change', => @deriveFields()
  
  @_setUpDerivations: ->
    @_derivations ||= []
    if @_derivations == @__super__.constructor._derivations
      @_derivations = _.clone(@__super__.constructor._derivations) 

  @derivedField: (fieldName, derivationFunction) ->
    @_setUpDerivations()
    @_derivations.push
      field: fieldName
      func:  derivationFunction

  @prependDerivedField: (fieldName, derivationFunction) ->
    @_setUpDerivations()
    @_derivations.unshift
      field: fieldName
      func: derivationFunction
  
  deriveFields: ->  
    for derivation in @constructor._derivations
      result = {}
      result[derivation.field] = derivation.func(@)
      @set(result, silent: true)
  
{'fraction_non_alphanumeric': 0.13624299616632263, 'fraction_numerical': 0.0005897965202005308, 'mean_word_length': 2.876571428571429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '357595', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1098, 'n_words': 214}