Sha256: 6ad242ca366da55a3f60c0d6f95ac01981812460cc83404542e94fede37498a1

Contents?: true

Size: 901 Bytes

Versions: 27

Compression:

Stored size: 901 Bytes

Contents

/**
 * A partial implementation of a collection that can store records of
 * different model types.  Backbone.Collection tries to merge records
 * if they have the same id.
 */
pageflow.MultiCollection = function() {
  this.records = {};
  this.length = 0;
};

_.extend(pageflow.MultiCollection.prototype, {
  add: function(record) {
    if (!this.records[record.cid]) {
      this.records[record.cid] = record;
      this.length = _.keys(this.records).length;

      this.trigger('add', record);
    }
  },

  remove: function(record) {
    if (this.records[record.cid]) {
      delete this.records[record.cid];
      this.length = _.keys(this.records).length;

      this.trigger('remove', record);
    }
  },

  isEmpty: function() {
    return this.length === 0;
  }
});

_.extend(pageflow.MultiCollection.prototype, Backbone.Events);

pageflow.MultiCollection.extend = Backbone.Collection.extend;

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pageflow-0.11.4 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.11.3 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.11.2 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.11.1 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.11.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.10.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.9.2 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.9.1 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.9.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.8.2 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.8.1 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.8.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.7.2 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.7.1 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.7.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.6.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.5.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.4.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.3.0 app/assets/javascripts/pageflow/editor/collections/multi_collection.js
pageflow-0.2.1 app/assets/javascripts/pageflow/editor/collections/multi_collection.js