|
|
@@ -28,7 +28,7 @@ export const transitionProps = {
|
|
|
// in case the child is also an abstract component, e.g. <keep-alive>
|
|
|
// we want to recursively retrieve the real component to be rendered
|
|
|
function getRealChild (vnode: ?VNode): ?VNode {
|
|
|
- const compOptions = vnode && vnode.componentOptions
|
|
|
+ const compOptions: ?VNodeComponentOptions = vnode && vnode.componentOptions
|
|
|
if (compOptions && compOptions.Ctor.options.abstract) {
|
|
|
return getRealChild(getFirstComponentChild(compOptions.children))
|
|
|
} else {
|
|
|
@@ -38,27 +38,27 @@ function getRealChild (vnode: ?VNode): ?VNode {
|
|
|
|
|
|
export function extractTransitionData (comp: Component): Object {
|
|
|
const data = {}
|
|
|
- const options = comp.$options
|
|
|
+ const options: ComponentOptions = comp.$options
|
|
|
// props
|
|
|
for (const key in options.propsData) {
|
|
|
data[key] = comp[key]
|
|
|
}
|
|
|
// events.
|
|
|
// extract listeners and pass them directly to the transition methods
|
|
|
- const listeners = options._parentListeners
|
|
|
+ const listeners: ?Object = options._parentListeners
|
|
|
for (const key in listeners) {
|
|
|
data[camelize(key)] = listeners[key].fn
|
|
|
}
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
-function placeholder (h, rawChild) {
|
|
|
+function placeholder (h: Function, rawChild: VNode): ?VNode {
|
|
|
return /\d-keep-alive$/.test(rawChild.tag)
|
|
|
? h('keep-alive')
|
|
|
: null
|
|
|
}
|
|
|
|
|
|
-function hasParentTransition (vnode) {
|
|
|
+function hasParentTransition (vnode: VNode): ?boolean {
|
|
|
while ((vnode = vnode.parent)) {
|
|
|
if (vnode.data.transition) {
|
|
|
return true
|
|
|
@@ -66,7 +66,7 @@ function hasParentTransition (vnode) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function isSameChild (child, oldChild) {
|
|
|
+function isSameChild (child: VNode, oldChild: VNode): boolean {
|
|
|
return oldChild.key === child.key && oldChild.tag === child.tag
|
|
|
}
|
|
|
|
|
|
@@ -76,13 +76,13 @@ export default {
|
|
|
abstract: true,
|
|
|
|
|
|
render (h: Function) {
|
|
|
- let children = this.$slots.default
|
|
|
+ let children: ?Array<VNode> = this.$slots.default
|
|
|
if (!children) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// filter out text nodes (possible whitespaces)
|
|
|
- children = children.filter(c => c.tag)
|
|
|
+ children = children.filter((c: VNode) => c.tag)
|
|
|
/* istanbul ignore if */
|
|
|
if (!children.length) {
|
|
|
return
|
|
|
@@ -97,7 +97,7 @@ export default {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- const mode = this.mode
|
|
|
+ const mode: string = this.mode
|
|
|
|
|
|
// warn invalid mode
|
|
|
if (process.env.NODE_ENV !== 'production' &&
|
|
|
@@ -108,7 +108,7 @@ export default {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- const rawChild = children[0]
|
|
|
+ const rawChild: VNode = children[0]
|
|
|
|
|
|
// if this is a component root node and the component's
|
|
|
// parent container node also has transition, skip.
|
|
|
@@ -118,7 +118,7 @@ export default {
|
|
|
|
|
|
// apply transition data to child
|
|
|
// use getRealChild() to ignore abstract components e.g. keep-alive
|
|
|
- const child = getRealChild(rawChild)
|
|
|
+ const child: ?VNode = getRealChild(rawChild)
|
|
|
/* istanbul ignore if */
|
|
|
if (!child) {
|
|
|
return rawChild
|
|
|
@@ -131,15 +131,15 @@ export default {
|
|
|
// ensure a key that is unique to the vnode type and to this transition
|
|
|
// component instance. This key will be used to remove pending leaving nodes
|
|
|
// during entering.
|
|
|
- const id = `__transition-${this._uid}-`
|
|
|
- const key = child.key = child.key == null
|
|
|
+ const id: string = `__transition-${this._uid}-`
|
|
|
+ const key: string = child.key = child.key == null
|
|
|
? id + child.tag
|
|
|
: isPrimitive(child.key)
|
|
|
? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key)
|
|
|
: child.key
|
|
|
- const data = (child.data || (child.data = {})).transition = extractTransitionData(this)
|
|
|
- const oldRawChild = this._vnode
|
|
|
- const oldChild: any = getRealChild(oldRawChild)
|
|
|
+ const data: Object = (child.data || (child.data = {})).transition = extractTransitionData(this)
|
|
|
+ const oldRawChild: VNode = this._vnode
|
|
|
+ const oldChild: VNode = getRealChild(oldRawChild)
|
|
|
|
|
|
// mark v-show
|
|
|
// so that the transition module can hand over the control to the directive
|
|
|
@@ -150,7 +150,7 @@ export default {
|
|
|
if (oldChild && oldChild.data && !isSameChild(child, oldChild)) {
|
|
|
// replace old child transition data with fresh one
|
|
|
// important for dynamic transitions!
|
|
|
- const oldData = oldChild && (oldChild.data.transition = extend({}, data))
|
|
|
+ const oldData: Object = oldChild && (oldChild.data.transition = extend({}, data))
|
|
|
// handle transition mode
|
|
|
if (mode === 'out-in') {
|
|
|
// return placeholder node and queue update when leave finishes
|
|
|
@@ -161,8 +161,8 @@ export default {
|
|
|
}, key)
|
|
|
return placeholder(h, rawChild)
|
|
|
} else if (mode === 'in-out') {
|
|
|
- var delayedLeave
|
|
|
- var performLeave = () => { delayedLeave() }
|
|
|
+ let delayedLeave
|
|
|
+ const performLeave = () => { delayedLeave() }
|
|
|
mergeVNodeHook(data, 'afterEnter', performLeave, key)
|
|
|
mergeVNodeHook(data, 'enterCancelled', performLeave, key)
|
|
|
mergeVNodeHook(oldData, 'delayLeave', leave => {
|