Skip to content

Commit 37077ee

Browse files
committed
improve css transition logic
1 parent fba74c1 commit 37077ee

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

src/batcher.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var _ = require('./util')
66
*/
77

88
function Batcher () {
9-
this._preFlush = null
109
this.reset()
1110
}
1211

@@ -46,10 +45,6 @@ p.push = function (job) {
4645
*/
4746

4847
p.flush = function () {
49-
// before flush hook
50-
if (this._preFlush) {
51-
this._preFlush()
52-
}
5348
// do not cache length because more jobs might be pushed
5449
// as we run existing jobs
5550
for (var i = 0; i < this.queue.length; i++) {

src/transition/css.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
var _ = require('../util')
2-
var Batcher = require('../batcher')
3-
var batcher = new Batcher()
42
var transDurationProp = _.transitionProp + 'Duration'
53
var animDurationProp = _.animationProp + 'Duration'
64

75
/**
86
* Force layout before triggering transitions/animations
97
*/
108

11-
batcher._preFlush = function () {
9+
var justReflowed = false
10+
11+
function reflow () {
12+
if (justReflowed) return
13+
justReflowed = true
1214
/* jshint unused: false */
1315
var f = document.documentElement.offsetHeight
16+
_.nextTick(unlock)
17+
}
18+
19+
function unlock () {
20+
justReflowed = false
1421
}
1522

1623
/**
@@ -78,11 +85,8 @@ module.exports = function (el, direction, op, data, cb) {
7885
op()
7986
transitionType = getTransitionType(el, data, enterClass)
8087
if (transitionType === 1) {
81-
batcher.push({
82-
run: function () {
83-
classList.remove(enterClass)
84-
}
85-
})
88+
reflow()
89+
classList.remove(enterClass)
8690
// only listen for transition end if user has sent
8791
// in a callback
8892
if (cb) {
@@ -123,14 +127,6 @@ module.exports = function (el, direction, op, data, cb) {
123127
classList.add(leaveClass)
124128
transitionType = getTransitionType(el, data, leaveClass)
125129
if (transitionType) {
126-
if (transitionType === 1) {
127-
classList.remove(leaveClass)
128-
batcher.push({
129-
run: function () {
130-
classList.add(leaveClass)
131-
}
132-
})
133-
}
134130
endEvent = data.event = transitionType === 1
135131
? _.transitionEndEvent
136132
: _.animationEndEvent

test/unit/specs/transition_spec.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,12 @@ if (_.inBrowser && !_.isIE9) {
207207
transition.apply(el, -1, op, vm, cb)
208208
expect(op).not.toHaveBeenCalled()
209209
expect(cb).not.toHaveBeenCalled()
210-
expect(el.classList.contains('test-leave')).toBe(false)
211-
_.nextTick(function () {
212-
expect(el.classList.contains('test-leave')).toBe(true)
213-
_.on(el, _.transitionEndEvent, function () {
214-
expect(op).toHaveBeenCalled()
215-
expect(cb).toHaveBeenCalled()
216-
expect(el.classList.contains('test-leave')).toBe(false)
217-
done()
218-
})
210+
expect(el.classList.contains('test-leave')).toBe(true)
211+
_.on(el, _.transitionEndEvent, function () {
212+
expect(op).toHaveBeenCalled()
213+
expect(cb).toHaveBeenCalled()
214+
expect(el.classList.contains('test-leave')).toBe(false)
215+
done()
219216
})
220217
})
221218
})

0 commit comments

Comments
 (0)