Browse Source

proper binding swapping in observed setters

Evan You 11 years ago
parent
commit
96f30c75de
1 changed files with 8 additions and 4 deletions
  1. 8 4
      src/observer/index.js

+ 8 - 4
src/observer/index.js

@@ -144,12 +144,16 @@ p.convert = function (key, val) {
       val = newVal
       var newBinding = ob.observe(newVal)
       if (newBinding) {
-        // handle over binding
-        newBinding.subs = binding.subs
-        binding.subs = []
+        // swap binding, then call notify on old binding.
+        // this ensures all subscribers of the old binding
+        // gets re-evaluated, picks up the new binding and
+        // unregister from old binding.
+        var oldBinding = binding
         binding = newBinding
+        oldBinding.notify()
+      } else {
+        binding.notify()
       }
-      binding.notify()
     }
   })
 }