mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-20 20:37:59 -05:00
Fix #1365 - Destroy: new models execute success callback.
This commit is contained in:
18
backbone.js
18
backbone.js
@@ -397,24 +397,24 @@
|
||||
var model = this;
|
||||
var success = options.success;
|
||||
|
||||
var triggerDestroy = function() {
|
||||
var destroy = function() {
|
||||
model.trigger('destroy', model, model.collection, options);
|
||||
};
|
||||
|
||||
options.success = function(resp) {
|
||||
if (options.wait || model.isNew()) destroy();
|
||||
if (success) success(model, resp, options);
|
||||
if (!model.isNew()) model.trigger('sync', model, resp, options);
|
||||
};
|
||||
|
||||
if (this.isNew()) {
|
||||
triggerDestroy();
|
||||
options.success();
|
||||
return false;
|
||||
}
|
||||
|
||||
options.success = function(resp) {
|
||||
if (options.wait) triggerDestroy();
|
||||
if (success) success(model, resp, options);
|
||||
model.trigger('sync', model, resp, options);
|
||||
};
|
||||
|
||||
options.error = Backbone.wrapError(options.error, model, options);
|
||||
var xhr = this.sync('delete', this, options);
|
||||
if (!options.wait) triggerDestroy();
|
||||
if (!options.wait) destroy();
|
||||
return xhr;
|
||||
},
|
||||
|
||||
|
||||
@@ -840,4 +840,11 @@ $(document).ready(function() {
|
||||
model.destroy();
|
||||
});
|
||||
|
||||
test("#1365 - Destroy: New models execute success callback.", 2, function() {
|
||||
new Backbone.Model()
|
||||
.on('sync', function() { ok(false); })
|
||||
.on('destroy', function(){ ok(true); })
|
||||
.destroy({ success: function(){ ok(true); }});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user