@@ -2,20 +2,38 @@ import { warn } from 'core/util/index'
2
2
import { noop , camelize } from 'shared/util'
3
3
import { getRealChild , mergeVNodeHook } from 'core/vdom/helpers'
4
4
5
+ export const transitionProps = {
6
+ name : String ,
7
+ appear : Boolean ,
8
+ css : Boolean ,
9
+ mode : String ,
10
+ enterClass : String ,
11
+ leaveClass : String ,
12
+ enterActiveClass : String ,
13
+ leaveActiveClass : String ,
14
+ appearClass : String ,
15
+ appearActiveClass : String
16
+ }
17
+
18
+ export function extractTransitionData ( comp ) {
19
+ const data = { }
20
+ const options = comp . $options
21
+ // props
22
+ for ( const key in options . propsData ) {
23
+ data [ key ] = comp [ key ]
24
+ }
25
+ // events.
26
+ // extract listeners and pass them directly to the transition methods
27
+ const listeners = options . _parentListeners
28
+ for ( const key in listeners ) {
29
+ data [ camelize ( key ) ] = listeners [ key ] . fn
30
+ }
31
+ return data
32
+ }
33
+
5
34
export default {
6
35
name : 'transition' ,
7
- props : {
8
- name : String ,
9
- appear : Boolean ,
10
- css : Boolean ,
11
- mode : String ,
12
- enterClass : String ,
13
- leaveClass : String ,
14
- enterActiveClass : String ,
15
- leaveActiveClass : String ,
16
- appearClass : String ,
17
- appearActiveClass : String
18
- } ,
36
+ props : transitionProps ,
19
37
_abstract : true ,
20
38
render ( h ) {
21
39
const children = this . $slots . default && this . $slots . default . filter ( c => c . tag )
@@ -41,26 +59,17 @@ export default {
41
59
// use getRealChild() to ignore abstract components e.g. keep-alive
42
60
const child = getRealChild ( rawChild )
43
61
child . key = child . key || `__v${ child . tag + this . _uid } __`
44
- const data = ( child . data || ( child . data = { } ) ) . transition = { }
45
- // props
46
- for ( const key in this . $options . propsData ) {
47
- data [ key ] = this [ key ]
48
- }
49
- // events.
50
- // extract listeners and pass them directly to the transition methods
51
- const listeners = this . $options . _parentListeners
52
- for ( const key in listeners ) {
53
- data [ camelize ( key ) ] = listeners [ key ] . fn
54
- }
62
+ const data = ( child . data || ( child . data = { } ) ) . transition = extractTransitionData ( this )
55
63
56
64
// handle transition mode
57
65
const mode = this . mode
58
66
const oldRawChild = this . _vnode
59
67
const oldChild = getRealChild ( oldRawChild )
60
68
if ( mode && oldChild && oldChild . data && oldChild . key !== child . key ) {
69
+ const oldData = oldChild . data . transition
61
70
if ( mode === 'out-in' ) {
62
71
// return empty node and queue update when leave finishes
63
- mergeVNodeHook ( oldChild . data . transition , 'afterLeave' , ( ) => {
72
+ mergeVNodeHook ( oldData , 'afterLeave' , ( ) => {
64
73
this . $forceUpdate ( )
65
74
} )
66
75
return / \d - k e e p - a l i v e $ / . test ( rawChild . tag )
@@ -73,7 +82,6 @@ export default {
73
82
mergeVNodeHook ( data , 'afterEnter' , performLeave )
74
83
mergeVNodeHook ( data , 'enterCancelled' , performLeave )
75
84
76
- const oldData = oldChild . data . transition
77
85
mergeVNodeHook ( oldData , 'delayLeave' , leave => {
78
86
delayedLeave = leave
79
87
} )
0 commit comments