Переглянути джерело

avoid directive updates when component is being destroyed

Evan You 11 роки тому
батько
коміт
d2db82f479
3 змінених файлів з 18 додано та 1 видалено
  1. 1 1
      src/directive.js
  2. 4 0
      src/directives/component.js
  3. 13 0
      test/unit/specs/directive_spec.js

+ 1 - 1
src/directive.js

@@ -75,7 +75,7 @@ p._bind = function (def) {
     // wrapped updater for context
     var dir = this
     var update = this._update = function (val, oldVal) {
-      if (!dir._locked) {
+      if (!dir._locked && !dir.vm._isBeingDestroyed) {
         dir.update(val, oldVal)
       }
     }

+ 4 - 0
src/directives/component.js

@@ -128,6 +128,10 @@ module.exports = {
         }
       }
       if (remove) {
+        // setting the "being destroyed" flag before
+        // removing to avoid content being changed during
+        // transitions
+        child._isBeingDestroyed = true
         child.$remove(destroy)
       } else {
         destroy()

+ 13 - 0
test/unit/specs/directive_spec.js

@@ -177,4 +177,17 @@ describe('Directive', function () {
     })
   })
 
+  it('avoid update when vm is being destroyed', function (done) {
+    var d = new Directive('test', el, vm, {
+      expression: 'a',
+    }, def)
+    expect(def.update.calls.count()).toBe(1)
+    vm._isBeingDestroyed = true
+    vm.a = 2
+    nextTick(function () {
+      expect(def.update.calls.count()).toBe(1)
+      done()
+    })
+  })
+
 })