Evan You 13 лет назад
Родитель
Сommit
5b96bdc556
2 измененных файлов с 14 добавлено и 6 удалено
  1. 8 4
      src/compiler.js
  2. 6 2
      src/viewmodel.js

+ 8 - 4
src/compiler.js

@@ -104,7 +104,7 @@ function Compiler (vm, options) {
         }
         }
     }
     }
 
 
-    // define root keys
+    // observe root keys
     var i = observables.length, binding
     var i = observables.length, binding
     while (i--) {
     while (i--) {
         binding = observables[i]
         binding = observables[i]
@@ -443,7 +443,7 @@ CompilerProto.bindContexts = function (bindings) {
  */
  */
 CompilerProto.destroy = function () {
 CompilerProto.destroy = function () {
     utils.log('compiler destroyed: ', this.vm.$el)
     utils.log('compiler destroyed: ', this.vm.$el)
-    var i, key, dir, inss,
+    var i, key, dir, inss, binding
         directives = this.directives,
         directives = this.directives,
         bindings = this.bindings,
         bindings = this.bindings,
         el = this.el
         el = this.el
@@ -457,10 +457,14 @@ CompilerProto.destroy = function () {
         }
         }
         dir.unbind()
         dir.unbind()
     }
     }
-    // unbind all own bindings
+    // unbind/unobserve all own bindings
     for (key in bindings) {
     for (key in bindings) {
+        binding = bindings[key]
         if (bindings.hasOwnProperty(key)) {
         if (bindings.hasOwnProperty(key)) {
-            bindings[key].unbind()
+            if (binding.root) {
+                Observer.unobserve(binding.value, binding.key, this.observer)
+            }
+            binding.unbind()
         }
         }
     }
     }
     // remove el
     // remove el

+ 6 - 2
src/viewmodel.js

@@ -12,11 +12,15 @@ function ViewModel (options) {
 
 
 var VMProto = ViewModel.prototype
 var VMProto = ViewModel.prototype
 
 
+/*
+ *  Convenience function to set an actual nested value
+ *  from a flat key string. Used in directives.
+ */
 VMProto.$set = function (key, value) {
 VMProto.$set = function (key, value) {
     var path = key.split('.'),
     var path = key.split('.'),
-        level = 0,
+        level = 0, l = path.length - 1
         target = this
         target = this
-    while (level < path.length - 1) {
+    while (level < l) {
         target = target[path[level]]
         target = target[path[level]]
         level++
         level++
     }
     }