<commit_before>/*

  collection class, forked from Backbone

*/

define([

  './Base',
  'lodash',
  './Model'

], function (Base, _, Model) {

  var _super = Base.prototype;

  // Wrap an optional error callback with a fallback error event.
  var wrapError = function (model, options) {
    var error = options.error;
    options.error = function(resp) {
      if (error) error(model, resp, options);
      model.trigger('error', model, resp, options);
    };
  };

  // Create local references to array methods we'll want to use later.
  var array = [];
  var push = array.push;
  var slice = array.slice;
  var splice = array.splice;

  // Default options for `Collection#set`.
  var setOptions = {add: true, remove: true, merge: true};
  var addOptions = {add: true, merge: false, remove: false};

  var Collection = Base.extend({

    'model': Model,

    'initialize': function (models, options) {

      var self = this;
      options || (options = {});
      this.options = options;
      _super.initialize.call(self, options);

      if (options.url) self.url = options.url;
      if (options.model) self.model = options.model;
      if (options.comparator !== void 0) self.comparator = options.comparator;
      self._reset();
      if (models) self.reset(models, _.extend({silent: true}, options));
    },

    // The JSON representation of a Collection is an array of the
    // models' attributes.
    toJSON: function(options) {
      return this.map(function(model){ return model.toJSON(options); });
    },

    // Add a model, or list of models to the set.
    add: function (models, collection, options) {

      var self = this;

      if (collection && !collection.models) {
        options = collection;
      }

      var result = self.set(models, _.defaults(options || {}, addOptions));

      if (!_.isArray(models)) {
        models = [models];
      }

      // self.logger.log(self.namespace+models.length);

      _.each(models, function (model) {
        _.each(model.attributes, function (value, key) {
          // self.logger.log('change?' + key + '::' + !!value);
          // !!value &&
          self.trigger('change:' + key, model, self);
        });
      });

      return result;
    },

    // Remove a model, or a list of models from the set.
    remove: function(models, options) {
      models = _.isArray(models) ? models.slice() : [models];
      options || (options = {});
      var i, l, index, model;
      for (i = 0, l = models.length; i < l; i++) {
        model = this.get(models[i]);
        if (!model) continue;
        delete this._byId[model.id];
        delete this._byId[model.cid];
        index = this.indexOf(model);
        this.models.splice(index, 1);
        this.length--;
        if (!options.silent) {
          options.index = index;
          model.trigger('remove', model, this, options);
        }
        this._removeReference(model);
      }
      return this;<commit_msg>going to solve this another way, want to keep this behavior, resolves #130<commit_after>/*

  collection class, forked from Backbone

*/

define([

  './Base',
  'lodash',
  './Model'

], function (Base, _, Model) {

  var _super = Base.prototype;

  // Wrap an optional error callback with a fallback error event.
  var wrapError = function (model, options) {
    var error = options.error;
    options.error = function(resp) {
      if (error) error(model, resp, options);
      model.trigger('error', model, resp, options);
    };
  };

  // Create local references to array methods we'll want to use later.
  var array = [];
  var push = array.push;
  var slice = array.slice;
  var splice = array.splice;

  // Default options for `Collection#set`.
  var setOptions = {add: true, remove: true, merge: true};
  var addOptions = {add: true, merge: false, remove: false};

  var Collection = Base.extend({

    'model': Model,

    'initialize': function (models, options) {

      var self = this;
      options || (options = {});
      this.options = options;
      _super.initialize.call(self, options);

      if (options.url) self.url = options.url;
      if (options.model) self.model = options.model;
      if (options.comparator !== void 0) self.comparator = options.comparator;
      self._reset();
      if (models) self.reset(models, _.extend({silent: true}, options));
    },

    // The JSON representation of a Collection is an array of the
    // models' attributes.
    toJSON: function(options) {
      return this.map(function(model){ return model.toJSON(options); });
    },

    // Add a model, or list of models to the set.
    add: function (models, collection, options) {

      var self = this;

      if (collection && !collection.models) {
        options = collection;
      }

      var result = self.set(models, _.defaults(options || {}, addOptions));

      if (!_.isArray(models)) {
        models = [models];
      }

      _.each(models, function (model) {
        _.each(model.attributes, function (value, key) {
          self.trigger('change:' + key, model, self);
        });
      });

      return result;
    },

    // Remove a model, or a list of models from the set.
    remove: function(models, options) {
      models = _.isArray(models) ? models.slice() : [models];
      options || (options = {});
      var i, l, index, model;
      for (i = 0, l = models.length; i < l; i++) {
        model = this.get(models[i]);
        if (!model) continue;
        delete this._byId[model.id];
        delete this._byId[model.cid];
        index = this.indexOf(model);
        this.models.splice(index, 1);
        this.length--;
        if (!options.silent) {
          options.index = index;
          model.trigger('remove', model, this, options);
        }
        this._removeReference(model);
      }
      return this;
{'fraction_non_alphanumeric': 0.14320137693631668, 'fraction_numerical': 0.001549053356282272, 'mean_word_length': 2.4042179261862917, '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': '2188707', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1701, 'n_words': 512}