瀏覽代碼

fix watcher accidentally clearing watcherList on teardown (fix #806)

Evan You 11 年之前
父節點
當前提交
e9670d59b0
共有 2 個文件被更改,包括 5 次插入2 次删除
  1. 4 1
      src/watcher.js
  2. 1 1
      test/unit/specs/directives/model_spec.js

+ 4 - 1
src/watcher.js

@@ -222,7 +222,10 @@ p.teardown = function () {
     // which can improve teardown performance.
     if (!this.vm._isBeingDestroyed) {
       var list = this.vm._watcherList
-      list.splice(list.indexOf(this))
+      var i = list.indexOf(this)
+      if (i > -1) {
+        list.splice(i, 1)
+      }
     }
     for (var id in this.deps) {
       this.deps[id].removeSub(this)

+ 1 - 1
test/unit/specs/directives/model_spec.js

@@ -233,7 +233,7 @@ if (_.inBrowser) {
         expect(opts[1].selected).toBe(false)
         // should teardown option watcher when unbind
         expect(vm._watcherList.length).toBe(2)
-        vm._directives[0].unbind()
+        vm._directives[0]._teardown()
         expect(vm._watcherList.length).toBe(0)
         done()
       })