Skip to content

Commit 0bb2087

Browse files
committed
comments for transition refactor
1 parent d03459c commit 0bb2087

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/transition/queue.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ var _ = require('../util')
22
var queue = []
33
var queued = false
44

5+
/**
6+
* Push a job into the queue.
7+
*
8+
* @param {Function} job
9+
*/
10+
511
exports.push = function (job) {
612
queue.push(job)
713
if (!queued) {

src/transition/transition.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ var doc = typeof document === 'undefined' ? null : document
1111
var TYPE_TRANSITION = 1
1212
var TYPE_ANIMATION = 2
1313

14+
/**
15+
* A Transition object that encapsulates the state and logic
16+
* of the transition.
17+
*
18+
* @param {Element} el
19+
* @param {String} id
20+
* @param {Object} hooks
21+
* @param {Vue} vm
22+
*/
23+
1424
function Transition (el, id, hooks, vm) {
1525
this.el = el
1626
this.enterClass = id + '-enter'
@@ -35,6 +45,13 @@ function Transition (el, id, hooks, vm) {
3545

3646
var p = Transition.prototype
3747

48+
/**
49+
* Start an entering transition.
50+
*
51+
* @param {Function} op - insert/show the element
52+
* @param {Function} [cb]
53+
*/
54+
3855
p.enter = function (op, cb) {
3956
this.cancelPending()
4057
this.callHook('beforeEnter')
@@ -44,6 +61,12 @@ p.enter = function (op, cb) {
4461
queue.push(this.nextEnter)
4562
}
4663

64+
/**
65+
* The "nextTick" phase of an entering transition, which is
66+
* to be pushed into a queue and executed after a reflow so
67+
* that removing the class can trigger a CSS transition.
68+
*/
69+
4770
p.nextEnter = function () {
4871
var enterHook = this.hooks && this.hooks.enter
4972
var afterEnter = this.afterEnter
@@ -67,13 +90,24 @@ p.nextEnter = function () {
6790
}
6891
}
6992

93+
/**
94+
* The "cleanup" phase of an entering transition.
95+
*/
96+
7097
p.afterEnter = function () {
7198
this.jsCancel = this.pendingJsCb = null
7299
removeClass(this.el, this.enterClass)
73100
this.callHook('afterEnter')
74101
if (this.cb) this.cb()
75102
}
76103

104+
/**
105+
* Start a leaving transition.
106+
*
107+
* @param {Function} op - remove/hide the element
108+
* @param {Function} [cb]
109+
*/
110+
77111
p.leave = function (op, cb) {
78112
this.cancelPending()
79113
this.callHook('beforeLeave')
@@ -95,6 +129,10 @@ p.leave = function (op, cb) {
95129
}
96130
}
97131

132+
/**
133+
* The "nextTick" phase of a leaving transition.
134+
*/
135+
98136
p.nextLeave = function () {
99137
var type = this.getCssTransitionType(this.leaveClass)
100138
if (type) {
@@ -107,13 +145,22 @@ p.nextLeave = function () {
107145
}
108146
}
109147

148+
/**
149+
* The "cleanup" phase of a leaving transition.
150+
*/
151+
110152
p.afterLeave = function () {
111153
this.op()
112154
removeClass(this.el, this.leaveClass)
113155
this.callHook('afterLeave')
114156
if (this.cb) this.cb()
115157
}
116158

159+
/**
160+
* Cancel any pending callbacks from a previously running
161+
* but not finished transition.
162+
*/
163+
117164
p.cancelPending = function () {
118165
this.op = this.cb = null
119166
var hasPending = false
@@ -137,12 +184,26 @@ p.cancelPending = function () {
137184
}
138185
}
139186

187+
/**
188+
* Call a user-provided hook function.
189+
*
190+
* @param {String} type
191+
*/
192+
140193
p.callHook = function (type) {
141194
if (this.hooks && this.hooks[type]) {
142195
this.hooks[type].call(this.vm, this.el)
143196
}
144197
}
145198

199+
/**
200+
* Get an element's transition type based on the
201+
* calculated styles.
202+
*
203+
* @param {String} className
204+
* @return {Number}
205+
*/
206+
146207
p.getCssTransitionType = function (className) {
147208
// skip CSS transitions if page is not visible -
148209
// this solves the issue of transitionend events not
@@ -175,6 +236,13 @@ p.getCssTransitionType = function (className) {
175236
return type
176237
}
177238

239+
/**
240+
* Setup a CSS transitionend/animationend callback.
241+
*
242+
* @param {String} event
243+
* @param {Function} cb
244+
*/
245+
178246
p.setupCssCb = function (event, cb) {
179247
this.pendingCssEvent = event
180248
var self = this

0 commit comments

Comments
 (0)