Permalink
Browse files

Fallback to ajaxSync for models and collections that are not using lo…

…calStorage
  • Loading branch information...
1 parent 70c15c0 commit ee89607a7330c23d29628e15ed331521d3748eac @thorlarholm committed Feb 21, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 backbone.localStorage.js
View
7 backbone.localStorage.js
@@ -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.
@@ -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;

0 comments on commit ee89607

Please sign in to comment.