@@ -37,7 +37,7 @@ function Transition (el, id, hooks, vm) {
37
37
this . typeCache = { }
38
38
// bind
39
39
var self = this
40
- ; [ 'nextEnter ' , 'afterEnter ' , 'nextLeave ' , 'afterLeave ' ]
40
+ ; [ 'enterNextTick ' , 'enterDone ' , 'leaveNextTick ' , 'leaveDone ' ]
41
41
. forEach ( function ( m ) {
42
42
self [ m ] = _ . bind ( self [ m ] , self )
43
43
} )
@@ -58,7 +58,7 @@ p.enter = function (op, cb) {
58
58
this . cb = cb
59
59
addClass ( this . el , this . enterClass )
60
60
op ( )
61
- queue . push ( this . nextEnter )
61
+ this . callHookWithCb ( 'enter' )
62
62
}
63
63
64
64
/**
@@ -67,37 +67,28 @@ p.enter = function (op, cb) {
67
67
* that removing the class can trigger a CSS transition.
68
68
*/
69
69
70
- p . nextEnter = function ( ) {
71
- var enterHook = this . hooks && this . hooks . enter
72
- var afterEnter = this . afterEnter
73
- var expectsCb
74
- if ( enterHook ) {
75
- expectsCb = enterHook . length > 1
76
- if ( expectsCb ) {
77
- this . pendingJsCb = _ . cancellable ( afterEnter )
78
- }
79
- this . jsCancel = enterHook . call ( this . vm , this . el , this . pendingJsCb )
80
- }
70
+ p . enterNextTick = function ( ) {
81
71
var type = this . getCssTransitionType ( this . enterClass )
72
+ var enterDone = this . enterDone
82
73
if ( type === TYPE_TRANSITION ) {
83
74
// trigger transition by removing enter class now
84
75
removeClass ( this . el , this . enterClass )
85
- this . setupCssCb ( transitionEndEvent , afterEnter )
76
+ this . setupCssCb ( transitionEndEvent , enterDone )
86
77
} else if ( type === TYPE_ANIMATION ) {
87
- this . setupCssCb ( animationEndEvent , afterEnter )
88
- } else if ( ! expectsCb ) {
89
- afterEnter ( )
78
+ this . setupCssCb ( animationEndEvent , enterDone )
79
+ } else {
80
+ enterDone ( )
90
81
}
91
82
}
92
83
93
84
/**
94
85
* The "cleanup" phase of an entering transition.
95
86
*/
96
87
97
- p . afterEnter = function ( ) {
88
+ p . enterDone = function ( ) {
98
89
this . jsCancel = this . pendingJsCb = null
99
90
removeClass ( this . el , this . enterClass )
100
- this . callHook ( 'afterEnter ' )
91
+ this . callHook ( 'enterDone ' )
101
92
if ( this . cb ) this . cb ( )
102
93
}
103
94
@@ -114,45 +105,33 @@ p.leave = function (op, cb) {
114
105
this . op = op
115
106
this . cb = cb
116
107
addClass ( this . el , this . leaveClass )
117
- var leaveHook = this . hooks && this . hooks . leave
118
- var expectsCb
119
- if ( leaveHook ) {
120
- expectsCb = leaveHook . length > 1
121
- if ( expectsCb ) {
122
- this . pendingJsCb = _ . cancellable ( this . afterLeave )
123
- }
124
- this . jsCancel = leaveHook . call ( this . vm , this . el , this . pendingJsCb )
125
- }
126
- // only need to handle leave cb if no js cb is provided
127
- if ( ! expectsCb ) {
128
- queue . push ( this . nextLeave )
129
- }
108
+ this . callHookWithCb ( 'leave' )
130
109
}
131
110
132
111
/**
133
112
* The "nextTick" phase of a leaving transition.
134
113
*/
135
114
136
- p . nextLeave = function ( ) {
115
+ p . leaveNextTick = function ( ) {
137
116
var type = this . getCssTransitionType ( this . leaveClass )
138
117
if ( type ) {
139
118
var event = type === TYPE_TRANSITION
140
119
? transitionEndEvent
141
120
: animationEndEvent
142
- this . setupCssCb ( event , this . afterLeave )
121
+ this . setupCssCb ( event , this . leaveDone )
143
122
} else {
144
- this . afterLeave ( )
123
+ this . leaveDone ( )
145
124
}
146
125
}
147
126
148
127
/**
149
128
* The "cleanup" phase of a leaving transition.
150
129
*/
151
130
152
- p . afterLeave = function ( ) {
131
+ p . leaveDone = function ( ) {
153
132
this . op ( )
154
133
removeClass ( this . el , this . leaveClass )
155
- this . callHook ( 'afterLeave ' )
134
+ this . callHook ( 'leaveDone ' )
156
135
if ( this . cb ) this . cb ( )
157
136
}
158
137
@@ -185,7 +164,7 @@ p.cancelPending = function () {
185
164
}
186
165
187
166
/**
188
- * Call a user-provided hook function.
167
+ * Call a user-provided synchronous hook function.
189
168
*
190
169
* @param {String } type
191
170
*/
@@ -196,6 +175,31 @@ p.callHook = function (type) {
196
175
}
197
176
}<
F438
/span>
198
177
178
+ /**
179
+ * Call a user-provided, potentially-async hook function.
180
+ * We check for the length of arguments to see if the hook
181
+ * expects a `done` callback. If true, the transition's end
182
+ * will be determined by when the user calls that callback;
183
+ * otherwise, the end is determined by the CSS transition or
184
+ * animation.
185
+ *
186
+ * @param {String } type
187
+ */
188
+
189
+ p . callHookWithCb = function ( type ) {
190
+ var hook = this . hooks && this . hooks [ type ]
191
+ if ( hook ) {
192
+ if ( hook . length > 1 ) {
193
+ this . pendingJsCb = _ . cancellable ( this [ type + 'Done' ] )
194
+ }
195
+ this . jsCancel = hook . call ( this . vm , this . el , this . pendingJsCb )
196
+ }
197
+ // only need to handle nextTick stuff if no js cb is provided
198
+ if ( ! this . pendingJsCb ) {
199
+ queue . push ( this [ type + 'NextTick' ] )
200
+ }
201
+ }
202
+
199
203
/**
200
204
* Get an element's transition type based on the
201
205
* calculated styles.
0 commit comments