Skip to content

Commit

Permalink
fixing bizzare version string test in Backbone.localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 19, 2013
1 parent 0a8509d commit 8bf56c6
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions examples/backbone.localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ _.extend(Backbone.LocalStorage.prototype, {
localStorage: function() {
return localStorage;
},

// fix for "illegal access" error on Android when JSON.parse is passed null
jsonData: function (data) {
return data && JSON.parse(data);
Expand All @@ -114,7 +114,7 @@ _.extend(Backbone.LocalStorage.prototype, {
Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(method, model, options) {
var store = model.localStorage || model.collection.localStorage;

var resp, errorMessage, syncDfd = $.Deferred && $.Deferred(); //If $ is having Deferred - use it.
var resp, errorMessage, syncDfd = $.Deferred && $.Deferred(); //If $ is having Deferred - use it.

try {

Expand Down Expand Up @@ -143,30 +143,26 @@ Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(m
if (resp) {
model.trigger("sync", model, resp, options);
if (options && options.success)
if (Backbone.VERSION === "0.9.10") {
options.success(model, resp, options);
} else {
options.success(resp);
}
options.success(resp);
if (syncDfd)
syncDfd.resolve(resp);

} else {
errorMessage = errorMessage ? errorMessage
: "Record Not Found";

model.trigger("error", model, errorMessage, options);
if (options && options.error)
if (Backbone.VERSION === "0.9.10") {
options.error(model, errorMessage, options);
} else {
options.error(errorMessage);
}

if (syncDfd)
syncDfd.reject(errorMessage);
}

// add compatibility with $.ajax
// always execute callback for success and error
if (options && options.complete) options.complete(resp);
Expand All @@ -191,4 +187,4 @@ Backbone.sync = function(method, model, options) {
};

return Backbone.LocalStorage;
}));
}));

0 comments on commit 8bf56c6

Please sign in to comment.