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 :
d2/sdk/models/mixins/resource.mixin
- instance
- static
- .mixin(prototype) ⇒
void
- .mixin(prototype) ⇒
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.
Param | Type | Description |
---|---|---|
options | object | Options hash |
options.connector | Connector | 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
Param | Type | Description |
---|---|---|
prototype | Object | The target prototype where the mixin methods will be fused. |