<commit_before>(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['react', 'backbone', 'underscore'], factory);
  } else if (typeof module !== 'undefined' && module.exports) {
    module.exports = factory(require('react'), require('backbone'), require('underscore'));
  } else {
    root.ReactBackboneHandlerMixin = factory(root.React, root.Backbone, root._);
  }
}(this, function (React, Backbone, _) {

  ReactBackboneHandlerMixin = {
    getInitializeModelState: function(props) {
      var state = {};
      this.eachHandleModels(props, function(fields, modelName, model) {
        return _(fields).each(function(stateFieldName, modelFieldName) {
          return state[stateFieldName] = model.get('modelFieldName');
        })
      });
      return state;
    },
    /**
     * User method for handling change events
     *
     * Use:
     * <input ... onChange={this.handleChangeEvent.bind(this, 'post', 'title')} />
     *
     * @param {String} modelName Name of model from `handleModels`
     * @param {String} fieldName Name of model field from `handleModels`
     * @param {React.Event} event React event for give change val
     */
    handleChangeEvent: function(modelName, fieldName, event) {
      return this.handleChangeValue(modelName, fieldName, $(e.target).val());
    },
    /**
     * User method for handling change value of model
     *
     * @param {String} modelName Name of model from `handleModels`
     * @param {String} fieldName Name of model field from `handleModels`
     * @param {String|Integer|Object} value New value
     */
    handleChangeValue: function(modelName, fieldName, value) {
      return this.props[modelName].set(fieldName, value);
    }
    /**
     * Assign change models listners.
     * If autobinding is on.
     * @params {Object} - current props object
     */
    bindModelListners: function(props) {
      if (this.autobinding) {
        return this.eachHandleModels(props, function(fields, modelName) {
          return _(fields).each(_(function(stateFieldName, modelFieldName) {
            var changeEvent = 'change:' + modelFieldName,
            handler = this.getChangeValueHandler(stateFieldName);
            return this.listenTo(props[modelName], changeEvent, handler);
          }).bind(this));
        });
      }
    },
    /**
     * Build callback for change state by changed model attribute
     * @params {String}
     */
    getChangeValueHandler: function(stateFieldName) {
      return _(function(model, value, options) {
        var newState = {};
        newState[stateFieldName] = value;
        return this.setState(newState);
      }).bind(this);
    },
    /**
     * Remove change model listner
     * If autobinding is on.
     * @params {Object} - current props object
     */
    unbindModelListners: function(props) {
      if (this.autobinding) {
        return this.eachHandleModels(props, function(fields, modelName) {
          return this.stopListening(props[modelName]);
        });
      }
    },
    /**
     * Each models for handling if this models exist in props
     */
    eachHandleModels: function(props, callback) {
      return _(this.handleModels).each(_(function(fields, modelName) {
        if (_(props[modelName]).isObject()) {
          return callback.apply(this, fields, modelName, props[modelName]);
        } else {
          throw "Model \"" + modelName + "\" is not exist in props";
        }
      }).bind(this));
    },
    componentWillMount: function() {
      _.extend(object, Backbone.Events);
      return this.bindModelListners(this.props);
    },
    componentWillUnmount: function() {
      return this.unbindModelListners(this.props);
    },
    componentWillReceiveProps: function(newProps) {
      this.unbindModelListners(this.props);
      this.bindModelListners(newProps);

      return this.eachHandleModels(newProps, function(fields, modelName) {
        var newState = {};
        _(fields).each(function(stateFieldName, modelFieldName) {
          return newState[stateFieldName] = newProps.get(modelFieldName);
        });
        return this.setState(newState);
      });
    }
  };

  return ReactBackboneHandlerMixin;
}));<commit_msg>Lint code<commit_after>(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['react', 'backbone', 'underscore'], factory);
  } else if (typeof module !== 'undefined' && module.exports) {
    module.exports = factory(require('react'), require('backbone'), require('underscore'));
  } else {
    root.ReactBackboneHandlerMixin = factory(root.React, root.Backbone, root._);
  }
}(this, function (React, Backbone, _) {
  'use strict';

  ReactBackboneHandlerMixin = {
    getInitializeModelState: function(props) {
      var state = {};
      this.eachHandleModels(props, function(fields, modelName, model) {
        return _(fields).each(function(stateFieldName, modelFieldName) {
          state[stateFieldName] = model.get('modelFieldName');
          return;
        });
      });
      return state;
    },
    /**
     * User method for handling change events
     *
     * Use:
     * <input ... onChange={this.handleChangeEvent.bind(this, 'post', 'title')} />
     *
     * @param {String} modelName Name of model from `handleModels`
     * @param {String} fieldName Name of model field from `handleModels`
     * @param {React.Event} event React event for give change val
     */
    handleChangeEvent: function(modelName, fieldName, event) {
      return this.handleChangeValue(modelName, fieldName, $(e.target).val());
    },
    /**
     * User method for handling change value of model
     *
     * @param {String} modelName Name of model from `handleModels`
     * @param {String} fieldName Name of model field from `handleModels`
     * @param {String|Integer|Object} value New value
     */
    handleChangeValue: function(modelName, fieldName, value) {
      return this.props[modelName].set(fieldName, value);
    },
    /**
     * Assign change models listners.
     * If autobinding is on.
     * @params {Object} - current props object
     */
    bindModelListners: function(props) {
      if (this.autobinding) {
        return this.eachHandleModels(props, function(fields, modelName) {
          return _(fields).each(_(function(stateFieldName, modelFieldName) {
            var changeEvent = 'change:' + modelFieldName,
            handler = this.getChangeValueHandler(stateFieldName);
            return this.listenTo(props[modelName], changeEvent, handler);
          }).bind(this));
        });
      }
    },
    /**
     * Build callback for change state by changed model attribute
     * @params {String}
     */
    getChangeValueHandler: function(stateFieldName) {
      return _(function(model, value, options) {
        var newState = {};
        newState[stateFieldName] = value;
        return this.setState(newState);
      }).bind(this);
    },
    /**
     * Remove change model listner
     * If autobinding is on.
     * @params {Object} - current props object
     */
    unbindModelListners: function(props) {
      if (this.autobinding) {
        return this.eachHandleModels(props, function(fields, modelName) {
          return this.stopListening(props[modelName]);
        });
      }
    },
    /**
     * Each models for handling if this models exist in props
     */
    eachHandleModels: function(props, callback) {
      return _(this.handleModels).each(_(function(fields, modelName) {
        if (_(props[modelName]).isObject()) {
          return callback.apply(this, fields, modelName, props[modelName]);
        } else {
          throw "Model \"" + modelName + "\" is not exist in props";
        }
      }).bind(this));
    },
    componentWillMount: function() {
      _.extend(object, Backbone.Events);
      return this.bindModelListners(this.props);
    },
    componentWillUnmount: function() {
      return this.unbindModelListners(this.props);
    },
    componentWillReceiveProps: function(newProps) {
      this.unbindModelListners(this.props);
      this.bindModelListners(newProps);

      return this.eachHandleModels(newProps, function(fields, modelName) {
        var newState = {};
        _(fields).each(function(stateFieldName, modelFieldName) {
          newState[stateFieldName] = newProps.get(modelFieldName);
          return;
        });
        return this.setState(newState);
      });
    }
  };

  return ReactBackboneHandlerMixin;
}));
{'fraction_non_alphanumeric': 0.12682869277961303, 'fraction_numerical': 0.0, 'mean_word_length': 2.8357466063348418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6120234', 'n_tokens_mistral': 2375, 'n_tokens_neox': 2380, 'n_words': 551}