<commit_before>var objectAssign = require('object-assign'),
  behaviorSelector = require('./behaviorSelector');

function forEachProperty(propertiesDefinitionObject, func) {
  var propertyNames = [];
  if (propertiesDefinitionObject) {
    propertyNames = Object.keys(propertiesDefinitionObject);
  }
  for (var i = 0; i < propertyNames.length; i++) {
    if (func(propertyNames[i], i) === true) {
      break;
    }
  }
}

function getDefaultState(schema) {
  var defaultState = {
    val: Object.create(null)
  };

  forEachProperty(schema.properties, function (prop) {
    var childSchema = schema.properties[prop];
    defaultState.val[prop] = behaviorSelector.getDefaultState(childSchema);
  });

  return defaultState;
}

function constructState(schema, stateArg, overrides) {
  var state = stateArg || getDefaultState(schema);
  var retval = objectAssign({}, state);

  if (typeof overrides !== 'undefined') {
    objectAssign(retval, overrides);
    if (typeof overrides.val !== 'undefined') {
      if (typeof schema.setDataTransform === 'function') {
        retval.val = schema.setDataTransform(retval.val);
      }

      var valState = Object.create(null);
      forEachProperty(schema.properties, function (prop) {
        var childSchema = schema.properties[prop];
        var childState = state.val[prop];
        var childOverrides = objectAssign({}, overrides, { val: retval.val[prop] });
        if (!retval.val.hasOwnProperty(prop)) {
          delete childOverrides.val;
        }

        valState[prop] = behaviorSelector.constructState(childSchema, childState, childOverrides);
      });
      retval.val = valState;
    }
  }

  return retval;
}

function deconstructState(schema, getState) {
  var retval = Object.create(null);

  forEachProperty(schema.properties, function (prop) {
    var childSchema = schema.properties[prop];<commit_msg>Fixed overrides propagation to children<commit_after>var objectAssign = require('object-assign'),
  behaviorSelector = require('./behaviorSelector');

function forEachProperty(propertiesDefinitionObject, func) {
  var propertyNames = [];
  if (propertiesDefinitionObject) {
    propertyNames = Object.keys(propertiesDefinitionObject);
  }
  for (var i = 0; i < propertyNames.length; i++) {
    if (func(propertyNames[i], i) === true) {
      break;
    }
  }
}

function getDefaultState(schema) {
  var defaultState = {
    val: Object.create(null)
  };

  forEachProperty(schema.properties, function (prop) {
    var childSchema = schema.properties[prop];
    defaultState.val[prop] = behaviorSelector.getDefaultState(childSchema);
  });

  return defaultState;
}

function constructState(schema, stateArg, overrides) {
  var state = stateArg || getDefaultState(schema);
  var retval = objectAssign({}, state);

  if (typeof overrides !== 'undefined') {
    objectAssign(retval, overrides);
    if (typeof overrides.val !== 'undefined') {
      if (typeof schema.setDataTransform === 'function') {
        retval.val = schema.setDataTransform(retval.val);
      }

      var valState = Object.create(null);
      forEachProperty(schema.properties, function (prop) {
        var childSchema = schema.properties[prop];
        var childState = state.val[prop];
        var childOverrides = objectAssign({}, overrides, { val: retval.val[prop] });
        if (!retval.val.hasOwnProperty(prop)) {
          delete childOverrides.val;
        }

        valState[prop] = behaviorSelector.constructState(childSchema, childState, childOverrides);
      });
      retval.val = valState;
    } else {
      var valState = Object.create(null);
      forEachProperty(schema.properties, function (prop) {
        var childSchema = schema.properties[prop];
        var childState = state.val[prop];
        valState[prop] = behaviorSelector.constructState(childSchema, childState, overrides);
      });
      retval.val = valState;
    }
  }

  return retval;
}

function deconstructState(schema, getState) {
  var retval = Object.create(null);

  forEachProperty(schema.properties, function (prop) {
    var childSchema = schema.properties[prop];
{'fraction_non_alphanumeric': 0.12432959531935642, 'fraction_numerical': 0.00048756704046806434, 'mean_word_length': 3.710677382319173, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1869616', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1147, 'n_words': 246}