Skip to content

Commit 99023c8

Browse files
author
Evan You
committed
simplify animation logic
1 parent 63e9d72 commit 99023c8

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/transition.js

+11-24
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ var endEvents = sniffEndEvents(),
2020
SKIP : -6
2121
}
2222

23-
// force a layout so transition can be triggered
24-
batcher._preFlush = function () {
25-
/* jshint unused: false */
26-
var forceLayout = document.body.clientHeight
27-
}
28-
2923
/**
3024
* stage:
3125
* 1 = enter
@@ -83,14 +77,12 @@ function applyTransitionClass (el, stage, changeState, hasAnimation) {
8377

8478
// if the browser supports transition,
8579
// it must have classList...
86-
var onEnd, job,
80+
var onEnd,
8781
classList = el.classList,
8882
existingCallback = el.vue_trans_cb,
8983
enterClass = config.enterClass,
9084
leaveClass = config.leaveClass,
91-
endEvent = hasAnimation
92-
? endEvents.anim
93-
: endEvents.trans
85+
endEvent = hasAnimation ? endEvents.anim : endEvents.trans
9486

9587
// cancel unfinished callbacks and jobs
9688
if (existingCallback) {
@@ -102,18 +94,17 @@ function applyTransitionClass (el, stage, changeState, hasAnimation) {
10294

10395
if (stage > 0) { // enter
10496

105-
// set to hidden state before appending
106-
if (!hasAnimation) {
107-
classList.add(enterClass)
108-
}
97+
// set to enter state before appending
98+
classList.add(enterClass)
10999
// append
110100
changeState()
111-
job = {}
112101
// trigger transition
113102
if (!hasAnimation) {
114-
job.execute = function () {
115-
classList.remove(enterClass)
116-
}
103+
batcher.push({
104+
execute: function () {
105+
classList.remove(enterClass)
106+
}
107+
})
117108
} else {
118109
onEnd = function (e) {
119110
if (e.target === el) {
@@ -122,13 +113,9 @@ function applyTransitionClass (el, stage, changeState, hasAnimation) {
122113
classList.remove(enterClass)
123114
}
124115
}
125-
job.execute = function () {
126-
classList.add(enterClass)
127-
el.addEventListener(endEvent, onEnd)
128-
el.vue_trans_cb = onEnd
129-
}
116+
el.addEventListener(endEvent, onEnd)
117+
el.vue_trans_cb = onEnd
130118
}
131-
batcher.push(job)
132119
return codes.CSS_E
133120

134121
} else { // leave

test/unit/specs/transition.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('UNIT: Transition', function () {
107107
var el = mockEl('css'),
108108
c = mockChange(function () {
109109
c.called = true
110-
assert.notOk(el.classList.contains(enterClass))
110+
assert.ok(el.classList.contains(enterClass))
111111
}),
112112
compiler = mockCompiler(),
113113
code
@@ -122,12 +122,12 @@ describe('UNIT: Transition', function () {
122122
document.body.removeChild(el)
123123
})
124124

125-
it('should not add enterClass before calling changeState()', function () {
125+
it('should add enterClass before calling changeState()', function () {
126126
code = transition(el, 1, c.change, compiler)
127127
assert.ok(c.called)
128128
})
129129

130-
it('should add the class on nextTick', function (done) {
130+
it('should still have the class on nextTick', function (done) {
131131
nextTick(function () {
132132
assert.ok(el.classList.contains(enterClass))
133133
done()

0 commit comments

Comments
 (0)