Skip to content

@jamespwright /BackboneJSFetch.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function (options) {
options = options ? _.clone(options) : {};
if (options.parse === undefined) options.parse = true;
var collection = this;
var success = options.success;
options.success = function(resp, status, xhr) {
collection[options.add ? 'add' : 'reset'](collection.parse(resp, xhr), options);
if (success) success(collection, resp);
};
options.error = Backbone.wrapError(options.error, collection, options);
return (this.sync || Backbone.sync).call(this, 'read', this, options);
}
sync: function(method, object, options) {
console.log(method);
options = (options) ? options : {};
var resp;
var localStore = this.dualStorage.localStorage;
var pickCallback = function(record) {
var logArgs = function(args) { console.log(args); };
options.success = (options.success) ? options.success : logArgs;
options.error = (options.error) ? options.error : logArgs;
if (record && record !== []) {
options.success(record);
} else {
options.error({ message: "Could not find record", record: record });
}
};
switch (method) {
case "readall": localStore.findAll(pickCallback); break;
case "read":
localStore.find(object, pickCallback);
break;
case "create": localStore.save(object, pickCallback); break;
case "update": localStore.save(object, pickCallback); break;
case "updateitem": localStore.saveItem(object, pickCallback); break;
case "delete": localStore.destroy(object, pickCallback); break;
case "deleteAll": localStore.destroyAll(object, pickCallback); break;
}
}
find: function(truthFunc, callback) {
this.getData(function(records) {
var items = _.filter(records, truthFunc);
callback(items);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.