mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 05:48:10 -05:00
Fix recursion error when saving from within a change event.
This commit is contained in:
@@ -242,9 +242,8 @@
|
||||
// If the server returns an attributes hash that differs, the model's
|
||||
// state will be `set` again.
|
||||
save : function(attrs, options) {
|
||||
attrs || (attrs = {});
|
||||
options || (options = {});
|
||||
if (!this.set(attrs, options)) return false;
|
||||
if (attrs && !this.set(attrs, options)) return false;
|
||||
var model = this;
|
||||
var success = function(resp) {
|
||||
if (!model.set(model.parse(resp), options)) return false;
|
||||
|
||||
@@ -151,6 +151,15 @@ $(document).ready(function() {
|
||||
model.change();
|
||||
equals(model.get('name'), 'Rob');
|
||||
});
|
||||
|
||||
test("Model: save within change event", function () {
|
||||
var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
|
||||
model.bind('change', function () {
|
||||
model.save();
|
||||
ok(_.isEqual(lastRequest[1], model));
|
||||
});
|
||||
model.set({lastName: 'Hicks'});
|
||||
});
|
||||
|
||||
test("Model: save", function() {
|
||||
doc.save({title : "Henry V"});
|
||||
|
||||
Reference in New Issue
Block a user