<commit_before>import utils from './utils'
import Vue from 'vue'

export default class BaseModel
  @singular: 'undefinedSingular'
  @plural: 'undefinedPlural'

  # indicate to Loki our 'primary keys' - it promises to make these fast to lookup by.
  @uniqueIndices: ['id']

  # list of other attributes to index
  @indices: []

  @searchableFields: []

  # whitelist of attributes to include when serializing the record.
  # leave null to serialize all attributes
  @serializableAttributes: null

  # what is the key to use when serializing the record?
  @serializationRoot: null

  constructor: (recordsInterface, attributes = {}) ->
    @processing = false # not returning/throwing on already processing rn
    @_version = 0
    @attributeNames = []
    @setErrors()
    Object.defineProperty(@, 'recordsInterface', value: recordsInterface, enumerable: false)
    Object.defineProperty(@, 'recordStore', value: recordsInterface.recordStore, enumerable: false)
    Object.defineProperty(@, 'remote', value: recordsInterface.remote, enumerable: false)
    @update(@defaultValues())
    @update(attributes)
    @buildRelationships() if @relationships?
    @afterConstruction()

  bumpVersion: ->
    @_version = @_version + 1

  afterConstruction: ->

  defaultValues: ->
    {}

  clone: ->
    cloneAttributes = _.transform @attributeNames, (clone, attr) =>
      if _.isArray(@[attr])
        clone[attr] = @[attr].slice(0)
      else
        clone[attr] = @[attr]
      true
    cloneRecord = new @constructor(@recordsInterface, cloneAttributes)
    cloneRecord.clonedFrom = @
    cloneRecord

  inCollection: =>
    @['$loki']# and @recordsInterface.collection.get(@['$loki'])

  update: (attributes) ->
    @baseUpdate(attributes)

  baseUpdate: (attributes) ->
    @bumpVersion()
    @attributeNames = _.union(@attributeNames, _.keys(attributes))
    _.forEach attributes, (value, key) =>
      Vue.set(@, key, value)
      true

    @recordsInterface.collection.update(@) if @inCollection()

  attributeIsModified: (attributeName) -><commit_msg>chore(refactor): use forEach instead of transform<commit_after>import utils from './utils'
import Vue from 'vue'

export default class BaseModel
  @singular: 'undefinedSingular'
  @plural: 'undefinedPlural'

  # indicate to Loki our 'primary keys' - it promises to make these fast to lookup by.
  @uniqueIndices: ['id']

  # list of other attributes to index
  @indices: []

  @searchableFields: []

  # whitelist of attributes to include when serializing the record.
  # leave null to serialize all attributes
  @serializableAttributes: null

  # what is the key to use when serializing the record?
  @serializationRoot: null

  constructor: (recordsInterface, attributes = {}) ->
    @processing = false # not returning/throwing on already processing rn
    @_version = 0
    @attributeNames = []
    @setErrors()
    Object.defineProperty(@, 'recordsInterface', value: recordsInterface, enumerable: false)
    Object.defineProperty(@, 'recordStore', value: recordsInterface.recordStore, enumerable: false)
    Object.defineProperty(@, 'remote', value: recordsInterface.remote, enumerable: false)
    @update(@defaultValues())
    @update(attributes)
    @buildRelationships() if @relationships?
    @afterConstruction()

  bumpVersion: ->
    @_version = @_version + 1

  afterConstruction: ->

  defaultValues: ->
    {}

  clone: ->
    cloneAttributes = {}
    _.forEach @attributeNames, (attr) =>
      if _.isArray(@[attr])
        cloneAttributes[attr] = @[attr].slice(0)
      else
        cloneAttributes[attr] = @[attr]
      true
    cloneAttributes.cloney = true
    cloneRecord = new @constructor(@recordsInterface, cloneAttributes)
    cloneRecord.clonedFrom = @
    cloneRecord

  inCollection: =>
    @['$loki']# and @recordsInterface.collection.get(@['$loki'])

  update: (attributes) ->
    @baseUpdate(attributes)

  baseUpdate: (attributes) ->
    @bumpVersion()
    @attributeNames = _.union(@attributeNames, _.keys(attributes))
    _.forEach(attributes, (value, key) =>
      Vue.set(@, key, value)
      return true
    )

    @recordsInterface.collection.update(@) if @inCollection()

  attributeIsModified: (attributeName) ->
{'fraction_non_alphanumeric': 0.12134189864382584, 'fraction_numerical': 0.0014275517487508922, 'mean_word_length': 3.8377445339470655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5705340', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1176, 'n_words': 328}