Pārlūkot izejas kodu

clean up in $destroy

Evan You 11 gadi atpakaļ
vecāks
revīzija
98c7715758
2 mainītis faili ar 15 papildinājumiem un 10 dzēšanām
  1. 11 3
      src/api/lifecycle.js
  2. 4 7
      src/instance/scope.js

+ 11 - 3
src/api/lifecycle.js

@@ -43,7 +43,6 @@ exports.$destroy = function (remove) {
   if (this._isDestroyed) {
     return
   }
-  this._isDestroyed = true
   this._callHook('beforeDestroy')
   // remove DOM element
   if (remove) {
@@ -53,8 +52,6 @@ exports.$destroy = function (remove) {
       this.$remove()
     }
   }
-  this.$el.__vue__ = null
-  this.$el = null
   var i
   // remove self from parent. only necessary
   // if this is called by the user.
@@ -79,5 +76,16 @@ exports.$destroy = function (remove) {
   while (i--) {
     this._directives[i]._teardown()
   }
+  // clean up
+  this._children =
+  this._watchers =
+  this._activeWatcher =
+  this.$el =
+  this.$el.__vue__ =
+  this._directives = null
+  // call the last hook...
+  this._isDestroyed = true
   this._callHook('afterDestroy')
+  // turn off all instance listeners.
+  this._emitter.off()
 }

+ 4 - 7
src/instance/scope.js

@@ -62,6 +62,7 @@ exports._initScope = function () {
 exports._teardownScope = function () {
   this.$observer.off()
   this._unsyncData()
+  this._data = null
   this.$scope = null
   if (this.$parent) {
     var pob = this.$parent.$observer
@@ -87,12 +88,9 @@ exports._teardownScope = function () {
 exports._setData = function (data) {
   this._data = data
   var scope = this.$scope
-  var noSync = this.$options._noSync
   var key
   // teardown old sync listeners
-  if (!noSync) {
-    this._unsyncData()
-  }
+  this._unsyncData()
   // delete keys not present in the new data
   for (key in scope) {
     if (
@@ -114,7 +112,7 @@ exports._setData = function (data) {
     }
   }
   // setup sync between scope and new data
-  if (!noSync) {
+  if (!this.$options._noSync) {
     this._syncData()
   }
 }
@@ -218,7 +216,6 @@ exports._syncData = function () {
   var data = this._data
   var scope = this.$scope
   var locked = false
-
   var listeners = this._syncListeners = {
     data: {
       set: guard(function (key, val) {
@@ -243,7 +240,6 @@ exports._syncData = function () {
       })
     }
   }
-
   // sync scope and original data.
   this.$observer
     .on('set:self', listeners.data.set)
@@ -298,4 +294,5 @@ exports._unsyncData = function () {
     .off('set:self', listeners.scope.set)
     .off('add:self', listeners.scope.add)
     .off('delete:self', listeners.scope.delete)
+  this._syncListeners = null
 }