[Pkg-javascript-commits] [backbone] 13/15: Fix recursion error when saving from within a change event.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.2
in repository backbone.

commit 57194beffa3ca8c01f050cb9ddab8b38e45590bf
Author: Matt <matt at zurb.com>
Date:   Mon Nov 22 20:49:33 2010 -0800

    Fix recursion error when saving from within a change event.
---
 backbone.js   | 3 +--
 test/model.js | 9 +++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/backbone.js b/backbone.js
index f8b9b0f..b39f371 100644
--- a/backbone.js
+++ b/backbone.js
@@ -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;
diff --git a/test/model.js b/test/model.js
index 8894987..c103b98 100644
--- a/test/model.js
+++ b/test/model.js
@@ -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"});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list