Skip to main content

resource.mixin

ResourceMixin : d2/sdk/models/mixins/resource.mixin

Resource mixin. Can be mixed with any Backbone.Model or Backbone.Collection to make it AJAX worthy.

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

define([
'nuc/lib/backbone',
'd2/sdk/models/mixins/resource.mixin'
], function(Backbone, ResourceMixin){
'use strict';

var MyModel = Backbone.Model.extend({
constructor: function MyModel(attr, options) {
options = options || {};
MyModel.__super__.constructor.call(this, attr, options);

this.makeResource(options);
}
});

ResourceMixin.mixin(MyModel.ptototype); //Can be equally mixed with a Backbone.Collection prototype

return MyModel;
});

resourceMixin.makeResource(options) ⇒ *

Does the necessary setup on an instance of Backbone.Model or Backbone.Collection so that it can connect & fetch resource from server using AJAX.

Kind: instance method of ResourceMixin
Returns: * - the model/collection instance itself.

ParamTypeDescription
optionsobject

Options hash

options.connectorConnector

The transport that lets the model or collection to connect to server. See ConnectorFactory

ResourceMixin.mixin(prototype) ⇒ void

Fuse the mixin methods to a prototype

Kind: static method of ResourceMixin
Mixes: ConnectableMixin, FetchableMixin

ParamTypeDescription
prototypeObject

The target prototype where the mixin methods will be fused.