<commit_before>var _ = require('lodash')
  ,EventEmitter = require('events').EventEmitter
  ,util = require('util')
  ,itemFuncs = require('./lib/item-functions')
  ,mapFuncs = require('./lib/map-functions')
  ,listFuncs = require('./lib/list-functions')
  ,funcNames = _.keys(_.extend({}, itemFuncs, mapFuncs, listFuncs))
  ,funcsByType = {item:itemFuncs,map:mapFuncs,list:listFuncs}

// ======================================================

var isImmutable = (function(){
  var immuts = {
    'string': 1,
    'number': 1,
    'function': 1,
    'boolean': 1,
    'undefined': 1
  }
  return function(val){
    if (val === null){
      return true
    }
    return immuts.hasOwnProperty(typeof val)
  }
})()

var makeDef = (function(){
  var validTypes = {item:1,map:1,list:1}
  return function(prop, def){
    def = _.extend({
      type: 'item', // 'item', 'map', 'list'
      validate: function(){}
    }, def)
    if (!def.hasOwnProperty('value')){
      def.value = getDefault(def.type)
    }
    if (!validTypes.hasOwnProperty(def.type)){
      throw new Error(util.format('invalid type: %s', def.type))
    }
    def.prop = prop
    if (def.type === 'item'){
      def.validate(def.value)
    } else {
      _.each(def.value, function(val){
        def.validate(val)
      })
    }
    return def
  }
})()

function getDefault(type){
  if (type === 'item'){
    return undefined
  } else if (type === 'map'){
    return {}
  } else if (type === 'list'){
    return []
  }
}

// ======================================================

function Store(args){
  EventEmitter.call(this);
  var defs = this._defs = {}
  _.each(args.data, function(val, prop){
    defs[prop] = makeDef(prop, {value:val})
  })
  _.each(args.defs, function(def, prop){
    defs[prop] = makeDef(prop, def)
  })
}<commit_msg>Add extra props for loadables<commit_after>var _ = require('lodash')
  ,EventEmitter = require('events').EventEmitter
  ,util = require('util')
  ,itemFuncs = require('./lib/item-functions')
  ,mapFuncs = require('./lib/map-functions')
  ,listFuncs = require('./lib/list-functions')
  ,funcNames = _.keys(_.extend({}, itemFuncs, mapFuncs, listFuncs))
  ,funcsByType = {item:itemFuncs,map:mapFuncs,list:listFuncs}

// ======================================================

var isImmutable = (function(){
  var immuts = {
    'string': 1,
    'number': 1,
    'function': 1,
    'boolean': 1,
    'undefined': 1
  }
  return function(val){
    if (val === null){
      return true
    }
    return immuts.hasOwnProperty(typeof val)
  }
})()

var makeDef = (function(){
  var validTypes = {item:1,map:1,list:1}
  return function(prop, def){
    def = _.extend({
      type: 'item', // 'item', 'map', 'list'
      validate: function(){}
    }, def)
    if (!def.hasOwnProperty('value')){
      def.value = getDefault(def.type)
    }
    if (!validTypes.hasOwnProperty(def.type)){
      throw new Error(util.format('invalid type: %s', def.type))
    }
    def.prop = prop
    if (def.type === 'item'){
      def.validate(def.value)
    } else {
      _.each(def.value, function(val){
        def.validate(val)
      })
    }
    return def
  }
})()

function getDefault(type){
  if (type === 'item'){
    return undefined
  } else if (type === 'map'){
    return {}
  } else if (type === 'list'){
    return []
  }
}

// ======================================================

function Store(args){
  EventEmitter.call(this)
  var defs = this._defs = {}
  _.each(args.data, function(val, prop){
    defs[prop] = makeDef(prop, {value:val})
  })
  _.each(args.defs, function(def, prop){
    defs[prop] = makeDef(prop, def)
  })
  _.each(_.keys(defs), function(prop){
    var def = defs[prop]
    if (def.loadable){
      _.each([
        prop+':loading',
        prop+':status',
        prop+':timestamp'
      ], function(extraProp){
        defs[extraProp] = makeDef(extraProp, {type:def.type})
      })
    }
  })
}
{'fraction_non_alphanumeric': 0.23061224489795917, 'fraction_numerical': 0.004081632653061225, 'mean_word_length': 3.149206349206349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2778794', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1333, 'n_words': 263}