From 20a2e3408a9f8a09c8db6fa3ffb05b47766f5112 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Wed, 9 Nov 2011 13:56:43 -0500 Subject: [PATCH] set _changing = false only if !alreadyChanging --- backbone.js | 6 ++++-- test/model.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backbone.js b/backbone.js index eab2e7a6..d5b01440 100644 --- a/backbone.js +++ b/backbone.js @@ -211,8 +211,10 @@ } // Fire the `"change"` event, if the model has been changed. - if (!alreadyChanging && !options.silent && this._changed) this.change(options); - this._changing = false; + if (!alreadyChanging) { + if (!options.silent && this._changed) this.change(options); + this._changing = false; + } return this; }, diff --git a/test/model.js b/test/model.js index c76e389f..4963248b 100644 --- a/test/model.js +++ b/test/model.js @@ -449,4 +449,13 @@ $(document).ready(function() { a.set({state: 'hello'}); }); + test("Model: Multiple nested calls to set", function() { + var model = new Backbone.Model({}); + model.bind('change', function() { + model.set({b: 1}); + model.set({a: 1}); + }) + .set({a: 1}); + }); + });