10000 fragment: destroy children before removal · Mat-Moo/vue@012bede · GitHub
[go: up one dir, main page]

Skip to content

Commit 012bede

Browse files
committed
fragment: destroy children before removal
1 parent 79f289a commit 012bede

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

src/directives/public/for.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ module.exports = {
325325
if (inDoc && staggerAmount) {
326326
var op = frag.staggerCb = _.cancellable(function () {
327327
frag.staggerCb = null
328-
frag.remove(true)
328+
frag.remove()
329329
})
330330
setTimeout(op, staggerAmount)
331331
} else {
332-
frag.remove(true)
332+
frag.remove()
333333
}
334334
},
335335

src/directives/public/if.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040

4141
insert: function () {
4242
if (this.elseFrag) {
43-
this.elseFrag.remove(true)
43+
this.elseFrag.remove()
4444
this.elseFrag = null
4545
}
4646
this.frag = this.factory.create(this._host, this._scope, this._frag)
@@ -49,7 +49,7 @@ module.exports = {
4949

5050
remove: function () {
5151
if (this.frag) {
52-
this.frag.remove(true)
52+
this.frag.remove()
5353
this.frag = null
5454
}
5555
if (this.elseFactory) {

src/fragment/fragment.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,18 @@ function singleBefore (target, withTransition) {
8989

9090
/**
9191
* Remove fragment, single node version
92-
*
93-
* @param {Boolean} [destroy]
9492
*/
9593

96-
function singleRemove (destroy) {
94+
function singleRemove () {
9795
this.inserted = false
9896
var shouldCallRemove = _.inDoc(this.node)
9997
var self = this
98+
self.callHook(destroyChild)
10099
transition.remove(this.node, this.vm, function () {
101100
if (shouldCallRemove) {
102101
self.callHook(detach)
103102
}
104-
if (destroy) {
105-
self.destroy()
106-
}
103+
self.destroy()
107104
})
108105
}
109106

@@ -130,21 +127,18 @@ function multiBefore (target, withTransition) {
130127

131128
/**
132129
* Remove fragment, multi-nodes version
133-
*
134-
* @param {Boolean} [destroy]
135130
*/
136131

137-
function multiRemove (destroy) {
132+
function multiRemove () {
138133
this.inserted = false
139134
var self = this
140135
var shouldCallRemove = _.inDoc(this.node)
136+
self.callHook(destroyChild)
141137
_.removeNodeRange(this.node, this.end, this.vm, this.frag, function () {
142138
if (shouldCallRemove) {
143139
self.callHook(detach)
144140
}
145-
if (destroy) {
146-
self.destroy()
147-
}
141+
self.destroy()
148142
})
149143
}
150144

@@ -160,6 +154,20 @@ function attach (child) {
160154
}
161155
}
162156

157+
/**
158+
* Call destroy for all contained instances,
159+
* with remove:false and defer:true.
160+
* Defer is necessary because we need to
161+
* keep the children to call detach hooks
162+
* on them.
163+
*
164+
* @param {Vue} child
165+
*/
166+
167+
function destroyChild (child) {
168+
child.$destroy(false, true)
169+
}
170+
163171
/**
164172
* Call detach hook for a Vue instance.
165173
*

src/instance/lifecycle.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ exports._bindDir = function (descriptor, node, host, scope, frag) {
123123

124124
exports._destroy = function (remove, deferCleanup) {
125125
if (this._isBeingDestroyed) {
126+
this._cleanup()
126127
return
127128
}
128129
this._callHook('beforeDestroy')
@@ -142,10 +143,6 @@ exports._destroy = function (remove, deferCleanup) {
142143
}
143144
}
144145
}
145-
// remove self from owner fragment
146-
if (this._frag) {
147-
this._frag.children.$remove(this)
148-
}
149146
// destroy all children.
150147
i = this.$children.length
151148
while (i--) {
@@ -186,6 +183,15 @@ exports._destroy = function (remove, deferCleanup) {
186183
*/
187184

188185
exports._cleanup = function () {
186+
if (this._isDestroyed) {
187+
return
188+
}
189+
// remove self from owner fragment
190+
// do it in cleanup so that we can call $destroy with
191+
// defer right when a fragment is about to be removed.
192+
if (this._frag) {
193+
this._frag.children.$remove(this)
194+
}
189195
// remove reference from data ob
190196
// frozen object may not have observer.
191197
if (this._data.__ob__) {

0 commit comments

Comments
 (0)
0