<commit_before>import LayerModel from './LayerModel';
import Backbone from 'backbone';

/**
 * @memberof core/models
 */

class LayersCollection extends Backbone.Collection {
  getLayerById(id) {
    return this.find(layer => (layer.get('identifier') === id));
  }
}

LayersCollection.prototype.model = LayerModel;


export default LayersCollection;<commit_msg>Allowing intrinsic sorting in LayersCollection<commit_after>import LayerModel from './LayerModel';
import Backbone from 'backbone';

/**
 * @memberof core/models
 */

const LayersCollection = Backbone.Collection.extend({
  model: LayerModel,
  comparator: 'ordinal',

  /**
   * Add a single model or an array of models to the collection. Automtically
   * sets the 'ordinal' property for sorting.
   */
  add(layerDefinition, options) {
    if (Array.isArray(layerDefinition)) {
      for (let i = 0; i < layerDefinition.length; ++i) {
        layerDefinition[i].ordinal = this.size() + i;
      }
    }
    else {
      layerDefinition.ordinal = this.size();
    }
    return Backbone.Collection.prototype.add.call(this, layerDefinition, options);
  },
});

export default LayersCollection;
{'fraction_non_alphanumeric': 0.12315698178664354, 'fraction_numerical': 0.0008673026886383347, 'mean_word_length': 3.889830508474576, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '7539769', 'n_tokens_mistral': 347, 'n_tokens_neox': 336, 'n_words': 87}