Skip to content

Don't set up css transition callback if there's a js callback. #1246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/transition/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ p.enterNextTick = function () {
_.nextTick(function () {
this.justEntered = false
}, this)
var type = this.getCssTransitionType(this.enterClass)
var enterDone = this.enterDone
if (type === TYPE_TRANSITION) {
// trigger transition by removing enter class now
var type = this.getCssTransitionType(this.enterClass)
if (!this.pendingJsCb) {
if (type === TYPE_TRANSITION) {
// trigger transition by removing enter class now
removeClass(this.el, this.enterClass)
this.setupCssCb(transitionEndEvent, enterDone)
} else if (type === TYPE_ANIMATION) {
this.setupCssCb(animationEndEvent, enterDone)
} else {
enterDone()
}
} else if (type === TYPE_TRANSITION) {
removeClass(this.el, this.enterClass)
this.setupCssCb(transitionEndEvent, enterDone)
} else if (type === TYPE_ANIMATION) {
this.setupCssCb(animationEndEvent, enterDone)
} else if (!this.pendingJsCb) {
enterDone()
}
}

Expand Down
44 changes: 44 additions & 0 deletions test/unit/specs/transition/transition_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,50 @@ if (_.inBrowser && !_.isIE9) {
}
})

it('css + js hook with callback before transitionend', function (done) {
document.body.removeChild(el)
el.classList.add('test')

// enter hook that expects a second argument
// indicates the user wants to control when the
// transition ends.
var enterCalled = false
hooks.enter = function (el, enterDone) {
enterCalled = true
setTimeout(function () {
enterDone()
testDone()
}, 20)
}

el.__v_trans = new Transition(el, 'test', hooks, vm)
transition.apply(el, 1, function () {
document.body.appendChild(el)
op()
}, vm, cb)
expect(hooks.beforeEnter).toHaveBeenCalled()
expect(op).toHaveBeenCalled()
expect(cb).not.toHaveBeenCalled()
expect(enterCalled).toBe(true)
_.nextTick(function () {
expect(el.classList.contains('test-enter')).toBe(false)
expect(hooks.afterEnter).not.toHaveBeenCalled()
_.on(el, _.transitionEndEvent, function () {
// callback should have been called, but only once, by the js callback
expect(cb).toHaveBeenCalled()
expect(cb.calls.count()).toBe(1)
expect(hooks.afterEnter).toHaveBeenCalled()
done()
})
})

// this is called by the enter hook
function testDone () {
expect(cb).toHaveBeenCalled()
expect(hooks.afterEnter).toHaveBeenCalled()
}
})

it('clean up unfinished css callback', function (done) {
el.__v_trans = new Transition(el, 'test', null, vm)
el.classList.add('test')
Expand Down