Skip to content

Commit

Permalink
disable fragment reactivity during removal (fix vuejs#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 31, 2015
1 parent 702b173 commit 52e8638
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ function directiveComparator (a, b) {
*/

function makeUnlinkFn (vm, dirs, context, contextDirs) {
return function unlink (destroying) {
function unlink (destroying) {
teardownDirs(vm, dirs, destroying)
if (context && contextDirs) {
teardownDirs(context, contextDirs)
}
}
// expose linked directives
unlink.dirs = dirs
return unlink
}

/**
Expand Down
42 changes: 29 additions & 13 deletions src/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ Fragment.prototype.callHook = function (hook) {
}
}

/**
* Destroy the fragment.
*/

Fragment.prototype.destroy = function () {
if (this.parentFrag) {
this.parentFrag.childFrags.$remove(this)
}
this.unlink()
}

/**
* Insert fragment before target, single node version
*
Expand All @@ -109,7 +98,7 @@ function singleRemove () {
this.inserted = false
var shouldCallRemove = inDoc(this.node)
var self = this
self.callHook(destroyChild)
this.beforeRemove()
removeWithTransition(this.node, this.vm, function () {
if (shouldCallRemove) {
self.callHook(detach)
Expand Down Expand Up @@ -147,7 +136,7 @@ function multiRemove () {
this.inserted = false
var self = this
var shouldCallRemove = inDoc(this.node)
self.callHook(destroyChild)
this.beforeRemove()
removeNodeRange(this.node, this.end, this.vm, this.frag, function () {
if (shouldCallRemove) {
self.callHook(detach)
Expand All @@ -156,6 +145,33 @@ function multiRemove () {
})
}

/**
* Prepare the fragment for removal.
* Most importantly, disable the watchers on all the
* directives so that the rendered content stays the same
* during removal.
*/

Fragment.prototype.beforeRemove = function () {
this.callHook(destroyChild)
var dirs = this.unlink.dirs
var i = dirs.length
while (i--) {
dirs[i]._watcher && dirs[i]._watcher.teardown()
}
}

/**
* Destroy the fragment.
*/

Fragment.prototype.destroy = function () {
if (this.parentFrag) {
this.parentFrag.childFrags.$remove(this)
}
this.unlink()
}

/**
* Call attach hook for a Vue instance.
*
Expand Down

0 comments on commit 52e8638

Please sign in to comment.