mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Issue #289. Enable the use of jQuery.Deferred by returning Deferred objects from save() and fetch() calls.
This commit is contained in:
17
backbone.js
17
backbone.js
@@ -279,8 +279,7 @@
|
||||
if (success) success(model, resp);
|
||||
};
|
||||
options.error = wrapError(options.error, model, options);
|
||||
(this.sync || Backbone.sync).call(this, 'read', this, options);
|
||||
return this;
|
||||
return (this.sync || Backbone.sync).call(this, 'read', this, options);
|
||||
},
|
||||
|
||||
// Set a hash of model attributes, and sync the model to the server.
|
||||
@@ -297,8 +296,7 @@
|
||||
};
|
||||
options.error = wrapError(options.error, model, options);
|
||||
var method = this.isNew() ? 'create' : 'update';
|
||||
(this.sync || Backbone.sync).call(this, method, this, options);
|
||||
return this;
|
||||
return (this.sync || Backbone.sync).call(this, method, this, options);
|
||||
},
|
||||
|
||||
// Destroy this model on the server. Upon success, the model is removed
|
||||
@@ -312,8 +310,7 @@
|
||||
if (success) success(model, resp);
|
||||
};
|
||||
options.error = wrapError(options.error, model, options);
|
||||
(this.sync || Backbone.sync).call(this, 'delete', this, options);
|
||||
return this;
|
||||
return (this.sync || Backbone.sync).call(this, 'delete', this, options);
|
||||
},
|
||||
|
||||
// Default URL for the model's representation on the server -- if you're
|
||||
@@ -522,8 +519,7 @@
|
||||
if (success) success(collection, resp);
|
||||
};
|
||||
options.error = wrapError(options.error, collection, options);
|
||||
(this.sync || Backbone.sync).call(this, 'read', this, options);
|
||||
return this;
|
||||
return (this.sync || Backbone.sync).call(this, 'read', this, options);
|
||||
},
|
||||
|
||||
// Create a new instance of a model in this collection. After the model
|
||||
@@ -543,7 +539,8 @@
|
||||
coll.add(nextModel);
|
||||
if (success) success(nextModel, resp);
|
||||
};
|
||||
return model.save(null, options);
|
||||
model.save(null, options);
|
||||
return model;
|
||||
},
|
||||
|
||||
// **parse** converts a response into a list of models to be added to the
|
||||
@@ -1024,7 +1021,7 @@
|
||||
}
|
||||
|
||||
// Make the request.
|
||||
$.ajax(params);
|
||||
return $.ajax(params);
|
||||
};
|
||||
|
||||
// Helpers
|
||||
|
||||
15
test/sync.js
15
test/sync.js
@@ -1,14 +1,11 @@
|
||||
$(document).ready(function() {
|
||||
|
||||
module("Backbone.sync");
|
||||
|
||||
// Variable to catch the last request.
|
||||
window.lastRequest = null;
|
||||
|
||||
// Stub out jQuery.ajax...
|
||||
$.ajax = function(obj) {
|
||||
lastRequest = obj;
|
||||
};
|
||||
module("Backbone.sync", {setup : function() {
|
||||
window.lastRequest = null;
|
||||
$.ajax = function(obj) {
|
||||
lastRequest = obj;
|
||||
};
|
||||
}});
|
||||
|
||||
var Library = Backbone.Collection.extend({
|
||||
url : function() { return '/library'; }
|
||||
|
||||
Reference in New Issue
Block a user