Skip to main content

collection.delayed.data.mixin

DelayedCollectionDataMixin : d2/sdk/models/mixins/collection.delayed.data.mixin

DelayedCollectionData mixin. Can be mixed with any Backbone.Collection to create an interface that can be used to retrieve additional data like permission, favorited status, location, etc. and associated those with each model to fully represent them in any view context. This additional data retrieval happens only after the primary collection data has been fetched and thus the name DelayedCollectionData.

Collections using this mixin must override fetchDelayedData() method to actually fetch the additional data and must call enableDelayedDataFetch() post construction to enable the lifycycle hooks associated with this mixin.

Extends: Object
See: ServerQueryUtils
Example (A typical collection using this mixin may look like)

define([
'nuc/lib/jquery',
'nuc/lib/backbone',
'd2/sdk/models/mixins/collection.delayed.data.mixin'
], function($, Backbone, DelayedCollectionDataMixin){
'use strict';

var MyCollection = Backbone.Collection.extend({
constructor: function MyCollection(models, options) {
options = options || {};
MyCollection.__super__.constructor.call(this, models, options);

this.enableDelayedDataFetch(options);
},

fetchDelayedData: function(options) {
var dfd = $.Deferred();

//Custom logic to fetch the delayed data
//once done, `dfd` should be resolved with the retrieved data.

return dfd.promise();
}
});

DelayedCollectionDataMixin.mixin(MyCollection.ptototype);

return MyCollection;
});

delayedCollectionDataMixin.enableDelayedDataFetch(options) ⇒ *

To enable binding on the collection lifecyle hooks that will later trigger fetchDelayedData() on every collection sync.

Kind: instance method of DelayedCollectionDataMixin
Returns: * - Reference to the same instance of the collection on which it is called.

ParamTypeDescription
optionsobject

constructor options as created and passed during instantiation of the collection.

options.mergeDelayedDataSilentlyboolean

This controls whether or not to merge the additional data on individual models in silent manner.

delayedCollectionDataMixin.fetchDelayedData(options) ⇒ jQuery.Promise

Triggered every time the collection fetches its primary data. An implementation of this function enables the actual additional data fetch. The default implementation basically does nothing.

Kind: instance abstract method of DelayedCollectionDataMixin
Returns: jQuery.Promise - The returned promise should be resolved with fetched additional data to indicate successful retrieval or should be rejected otherwise.

ParamTypeDescription
optionsobject

Input paramters for the invocation.

options.nodesArray.<string>

The list of id of all the models currently inside this collection.

DelayedCollectionDataMixin.mixin(prototype) ⇒ void

Fuse the mixin methods to a collection prototype

Kind: static method of DelayedCollectionDataMixin

ParamTypeDescription
prototypeObject

Target collection prototype where the mixin methods will be fused.