BrowsableV2ResponseMixin
Deserializes the collection state maintained by BrowsableMixin
and the
collection of items from the server response according to the V1 of the
REST API (/api/v2/members/favorites
), for example). The BrowsableMixin
or a mixin including it must be applied with this mixin together.
Browsing implementation and response parsing is supposed to be added by other mixins, according to the specifics of the server resource.
Example
var MyCollection = Backbone.Collection.extend({
constructor: function MyCollection(models, options) {
Backbone.Collection.prototype.constructor.apply(this, arguments);
this
.makeClientSideBrowsable(options)
.makeBrowsableV1Request(options)
.makeBrowsableV2Response(options);
},
url: function () {
// use `getBrowsableUrlQuery` to format the URL query or its part
},
parse: function (response, options) {
// use `parseBrowsedState` to update the browsing properties
// according to the server response and return the received part
// of the collection by calling `parseBrowsedItems`
}
});
ClientSideBrowsableMixin.mixin(MyCollection.prototype);
BrowsableV1RequestMixin.mixin(MyCollection.prototype);
BrowsableV2ResponseMixin.mixin(MyCollection.prototype);
makeBrowsableV2Response(options) : this
Must be called in the constructor to initialize the mixin functionality.
Expects the Backbone.Collection constructor options passed in. It calls
makeBrowsable
from BrowsableMixin
too.
parseBrowsedState(response, options) : nothing
Updates the browsing state from the server response. It expects the arguments
passed into the parse
method, where this method should be called.
parseBrowsedItems(response, options) : array of object literals
Gathers the items from the server response and returns them as an array, which can be used initialized the collection of models with.
See Also
ClientSideBrowsableMixin
, BrowsableV1RequestMixin