Skip to content

Commit

Permalink
simplify animation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan You committed Feb 24, 2014
1 parent 63e9d72 commit 99023c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
35 changes: 11 additions & 24 deletions src/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ var endEvents = sniffEndEvents(),
SKIP : -6
}

// force a layout so transition can be triggered
batcher._preFlush = function () {
/* jshint unused: false */
var forceLayout = document.body.clientHeight
}

/**
* stage:
* 1 = enter
Expand Down Expand Up @@ -83,14 +77,12 @@ function applyTransitionClass (el, stage, changeState, hasAnimation) {

// if the browser supports transition,
// it must have classList...
var onEnd, job,
var onEnd,
classList = el.classList,
existingCallback = el.vue_trans_cb,
enterClass = config.enterClass,
leaveClass = config.leaveClass,
endEvent = hasAnimation
? endEvents.anim
: endEvents.trans
endEvent = hasAnimation ? endEvents.anim : endEvents.trans

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

if (stage > 0) { // enter

// set to hidden state before appending
if (!hasAnimation) {
classList.add(enterClass)
}
// set to enter state before appending
classList.add(enterClass)
// append
changeState()
job = {}
// trigger transition
if (!hasAnimation) {
job.execute = function () {
classList.remove(enterClass)
}
batcher.push({
execute: function () {
classList.remove(enterClass)
}
})
} else {
onEnd = function (e) {
if (e.target === el) {
Expand All @@ -122,13 +113,9 @@ function applyTransitionClass (el, stage, changeState, hasAnimation) {
classList.remove(enterClass)
}
}
job.execute = function () {
classList.add(enterClass)
el.addEventListener(endEvent, onEnd)
el.vue_trans_cb = onEnd
}
el.addEventListener(endEvent, onEnd)
el.vue_trans_cb = onEnd
}
batcher.push(job)
return codes.CSS_E

} else { // leave
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('UNIT: Transition', function () {
var el = mockEl('css'),
c = mockChange(function () {
c.called = true
assert.notOk(el.classList.contains(enterClass))
assert.ok(el.classList.contains(enterClass))
}),
compiler = mockCompiler(),
code
Expand All @@ -122,12 +122,12 @@ describe('UNIT: Transition', function () {
document.body.removeChild(el)
})

it('should not add enterClass before calling changeState()', function () {
it('should add enterClass before calling changeState()', function () {
code = transition(el, 1, c.change, compiler)
assert.ok(c.called)
})

it('should add the class on nextTick', function (done) {
it('should still have the class on nextTick', function (done) {
nextTick(function () {
assert.ok(el.classList.contains(enterClass))
done()
Expand Down

0 comments on commit 99023c8

Please sign in to comment.