Explorar o código

proper binding swapping in observed setters

Evan You %!s(int64=11) %!d(string=hai) anos
pai
achega
96f30c75de
Modificáronse 1 ficheiros con 8 adicións e 4 borrados
  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()
     }
   })
 }