Skip to content

Commit 31db052

Browse files
committed
enable transition again for fragment insert/removal
1 parent 329987c commit 31db052

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

src/api/dom.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ exports.$remove = function (cb, withTransition) {
100100
if (cb) cb()
101101
}
102102
if (this._isFragment) {
103-
var frag = this._fragment
104-
_.mapNodeRange(this._fragmentStart, this._fragmentEnd, function (node) {
105-
// store nodes in the fragment
106-
frag.appendChild(node)
107-
})
108-
realCb()
103+
_.removeNodeRange(
104+
this._fragmentStart,
105+
this._fragmentEnd,
106+
this, this._fragment, realCb
107+
)
109108
} else {
110109
var op = withTransition === false
111110
? remove
@@ -130,19 +129,19 @@ exports.$remove = function (cb, withTransition) {
130129
function insert (vm, target, cb, withTransition, op1, op2) {
131130
target = query(target)
132131
var targetIsDetached = !_.inDoc(target)
132+
var op = withTransition === false || targetIsDetached
133+
? op1
134+
: op2
133135
var shouldCallHook =
134136
!targetIsDetached &&
135137
!vm._isAttached &&
136138
!_.inDoc(vm.$el)
137139
if (vm._isFragment) {
138140
_.mapNodeRange(vm._fragmentStart, vm._fragmentEnd, function (node) {
139-
op1(node, target)
141+
op(node, target, vm)
140142
})
141143
cb && cb()
142144
} else {
143-
var op = withTransition === false || targetIsDetached
144-
? op1
145-
: op2
146145
op(vm.$el, target, vm, cb)
147146
}
148147
if (shouldCallHook) {

src/fragment/fragment.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ Fragment.prototype.destroy = function () {
7777
*/
7878

7979
function singleBefore (target, withTransition) {
80+
this.inserted = true
8081
var method = withTransition !== false
8182
? transition.before
8283
: _.before
8384
method(this.node, target, this.vm)
84-
this.inserted = true
8585
if (_.inDoc(this.node)) {
8686
this.callHook(attach)
8787
}
@@ -94,10 +94,10 @@ function singleBefore (target, withTransition) {
9494
*/
9595

9696
function singleRemove (destroy) {
97+
this.inserted = false
9798
var shouldCallRemove = _.inDoc(this.node)
9899
var self = this
99100
transition.remove(this.node, this.vm, function () {
100-
self.inserted = false
101101
if (shouldCallRemove) {
102102
self.callHook(detach)
103103
}
@@ -111,13 +111,18 @@ function singleRemove (destroy) {
111111
* Insert fragment before target, multi-nodes version
112112
*
113113
* @param {Node} target
114+
* @param {Boolean} withTransition
114115
*/
115116

116-
function multiBefore (target) {
117+
function multiBefore (target, withTransition) {
118+
this.inserted = true
119+
var vm = this.vm
120+
var method = withTransition !== false
121+
? transition.before
122+
: _.before
117123
_.mapNodeRange(this.node, this.end, function (node) {
118-
_.before(node, target)
124+
method(node, target, vm)
119125
})
120-
this.inserted = true
121126
if (_.inDoc(this.node)) {
122127
this.callHook(attach)
123128
}
@@ -130,18 +135,17 @@ function multiBefore (target) {
130135
*/
131136

132137
function multiRemove (destroy) {
133-
var frag = this.frag
138+
this.inserted = false
139+
var self = this
134140
var shouldCallRemove = _.inDoc(this.node)
135-
_.mapNodeRange(this.node, this.end, function (node) {
136-
frag.appendChild(node)
141+
_.removeNodeRange(this.node, this.end, this.vm, this.frag, function () {
142+
if (shouldCallRemove) {
143+
self.callHook(detach)
144+
}
145+
if (destroy) {
146+
self.destroy()
147+
}
137148
})
138-
this.inserted = false
139-
if (shouldCallRemove) {
140-
this.callHook(detach)
141-
}
142-
if (destroy) {
143-
this.destroy()
144-
}
145149
}
146150

147151
/**

src/util/dom.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('./index')
22
var config = require('../config')
3+
var transition = require('../transition')
34

45
/**
56
* Query an element selector if it's not an element already.
@@ -327,3 +328,35 @@ exports.mapNodeRange = function (node, end, op) {
327328
}
328329
op(end)
329330
}
331+
332+
/**
333+
* Remove a range of nodes with transition, store
334+
* the nodes in a fragment with correct ordering,
335+
* and call callback when done.
336+
*
337+
* @param {Node} start
338+
* @param {Node} end
339+
* @param {Vue} vm
340+
* @param {DocumentFragment} frag
341+
* @param {Function} cb
342+
*/
343+
344+
exports.removeNodeRange = function (start, end, vm, frag, cb) {
345+
var done = false
346+
var removed = 0
347+
var nodes = []
348+
exports.mapNodeRange(start, end, function (node) {
349+
if (node === end) done = true
350+
nodes.push(node)
351+
transition.remove(node, vm, onRemoved)
352+
})
353+
function onRemoved () {
354+
removed++
355+
if (done && removed >= nodes.length) {
356+
for (var i = 0; i < nodes.length; i++) {
357+
frag.appendChild(nodes[i])
358+
}
359+
cb && cb()
360+
}
361+
}
362+
}

0 commit comments

Comments
 (0)