Skip to content

Commit f8e98ce

Browse files
committed
use "enter/leaveCancelled" hooks instead of returning it from enter/leave
1 parent b8213d8 commit f8e98ce

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/transition/transition.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Transition (el, id, hooks, vm) {
2929
// async state
3030
this.pendingCssEvent =
3131
this.pendingCssCb =
32-
this.jsCancel =
32+
this.cancel =
3333
this.pendingJsCb =
3434
this.op =
3535
this.cb = null
@@ -76,6 +76,7 @@ p.enter = function (op, cb) {
7676
addClass(this.el, this.enterClass)
7777
op()
7878
this.callHookWithCb('enter')
79+
this.cancel = this.hooks && this.hooks.enterCancelled
7980
queue.push(this.enterNextTick)
8081
}
8182

@@ -104,7 +105,7 @@ p.enterNextTick = function () {
104105
*/
105106

106107
p.enterDone = function () {
107-
this.jsCancel = this.pendingJsCb = null
108+
this.cancel = this.pendingJsCb = null
108109
removeClass(this.el, this.enterClass)
109110
this.callHook('afterEnter')
110111
if (this.cb) this.cb()
@@ -138,6 +139,7 @@ p.leave = function (op, cb) {
138139
this.cb = cb
139140
addClass(this.el, this.leaveClass)
140141
this.callHookWithCb('leave')
142+
this.cancel = this.hooks && this.hooks.enterCancelled
141143
// only need to do leaveNextTick if there's no explicit
142144
// js callback
143145
if (!this.pendingJsCb) {
@@ -166,6 +168,7 @@ p.leaveNextTick = function () {
166168
*/
167169

168170
p.leaveDone = function () {
171+
this.cancel = this.pendingJsCb = null
169172
this.op()
170173
removeClass(this.el, this.leaveClass)
171174
this.callHook('afterLeave')
@@ -194,9 +197,9 @@ p.cancelPending = function () {
194197
removeClass(this.el, this.enterClass)
195198
removeClass(this.el, this.leaveClass)
196199
}
197-
if (this.jsCancel) {
198-
this.jsCancel.call(null)
199-
this.jsCancel = null
200+
if (this.cancel) {
201+
this.cancel.call(this.vm, this.el)
202+
this.cancel = null
200203
}
201204
}
202205

@@ -229,7 +232,7 @@ p.callHookWithCb = function (type) {
229232
if (hook.length > 1) {
230233
this.pendingJsCb = _.cancellable(this[type + 'Done'])
231234
}
232-
this.jsCancel = hook.call(this.vm, this.el, this.pendingJsCb)
235+
hook.call(this.vm, this.el, this.pendingJsCb)
233236
}
234237
}
235238

test/unit/specs/transition/transition_spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,16 @@ if (_.inBrowser && !_.isIE9) {
456456
})
457457
})
458458

459-
it('optional cleanup callback', function (done) {
459+
it('cancel hook', function (done) {
460460
var cleanupSpy = jasmine.createSpy('js cleanup')
461461
var leaveSpy = jasmine.createSpy('js leave')
462+
var timeout
462463
hooks.enter = function (el, done) {
463-
var to = setTimeout(done, 30)
464-
return function () {
465-
clearTimeout(to)
466-
cleanupSpy()
467-
}
464+
timeout = setTimeout(done, 30)
465+
}
466+
hooks.enterCancelled = function () {
467+
clearTimeout(timeout)
468+
cleanupSpy()
468469
}
469470
hooks.leave = function (el, done) {
470471
expect(cleanupSpy).toHaveBeenCalled()

0 commit comments

Comments
 (0)