Skip to content

Commit

Permalink
Fallback to ajaxSync for models and collections that are not using lo…
Browse files Browse the repository at this point in the history
…calStorage
  • Loading branch information
thorlarholm committed Feb 21, 2012
1 parent 70c15c0 commit ee89607
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backbone.localStorage.js
Expand Up @@ -3,7 +3,7 @@
* https://github.com/jeromegn/Backbone.localStorage
*/

// A simple module to replace `Backbone.sync` with *localStorage*-based
// A simple module to enhance `Backbone.sync` with *localStorage*-based
// persistence. Models are given GUIDS, and saved into a JSON object. Simple
// as that.

Expand Down Expand Up @@ -84,6 +84,11 @@ Backbone.localSync = function(method, model, options, error) {
var resp;
var store = model.localStorage || model.collection.localStorage;

// Fallback to ajaxSync for models and collections that are not using localStorage
if (_.isFunction(store) === false) {
return Backbone.ajaxSync.call(this, method, model, options, error);
}

switch (method) {
case "read": resp = model.id != undefined ? store.find(model) : store.findAll(); break;
case "create": resp = store.create(model); break;
Expand Down

0 comments on commit ee89607

Please sign in to comment.