factory.js | |
---|---|
Sync Factory | |
Requires {object} with CRUD Interface [create, read, update, delete] Returns {Function} to map syncInterface to implementation of CRUD methods | define(['facade', 'utils'], function(facade, utils) {
var syncFactory,
_ = facade._,
duckTypeCheck = utils.lib.duckTypeCheck; |
Simple sync factory | syncFactory = function (implementation) {
var crudInterface = {};
_.each(['create','read','update','destroy'], function (method) {
crudInterface[method] = Function.prototype;
});
if (!duckTypeCheck(implementation, crudInterface)) {
throw new Error("syncFactory expected implementation argument with CRUD methods.");
} |
Interface for Backbone.sync | return function syncInterface(method, model, options) {
switch (method) {
case "read":
implementation.read(model, options);
break;
case "create":
implementation.create(model, options);
break;
case "update":
implementation.update(model, options);
break;
case "delete":
implementation.destroy(model, options);
break;
}
};
};
return syncFactory;
});
|