@@ -28,7 +28,7 @@ module.exports = {
28
28
// cache object, with its constructor id as the key.
29
29
this . keepAlive = this . _checkParam ( 'keep-alive' ) != null
30
30
// wait for event before insertion
31
- this . readyEvent = this . _checkParam ( 'wait-for' )
31
+ this . waitForEvent = this . _checkParam ( 'wait-for' )
32
32
// check ref
33
33
this . refID = this . _checkParam ( config . prefix + 'ref' )
34
34
if ( this . keepAlive ) {
@@ -66,15 +66,23 @@ module.exports = {
66
66
*/
67
67
68
68
initStatic : function ( ) {
69
- var child = this . build ( )
69
+ // wait-for
70
70
var anchor = this . anchor
71
+ var options
72
+ var waitFor = this . waitForEvent
73
+ if ( waitFor ) {
74
+ options = {
75
+ created : function ( ) {
76
+ this . $once ( waitFor , function ( ) {
77
+ this . $before ( anchor )
78
+ } )
79
+ }
80
+ }
81
+ }
82
+ var child = this . build ( options )
71
83
this . setCurrent ( child )
72
- if ( ! this . readyEvent ) {
84
+ if ( ! this . waitForEvent ) {
73
85
child . $before ( anchor )
74
- } else {
75
- child . $once ( this . readyEvent , function ( ) {
76
- child . $before ( anchor )
77
- } )
78
86
}
79
87
} ,
80
88
@@ -93,32 +101,38 @@ module.exports = {
93
101
* specified transition mode. Accepts a few additional
94
102
* arguments specifically for vue-router.
95
103
*
104
+ * The callback is called when the full transition is
105
+ * finished.
106
+ *
96
107
* @param {String } value
97
- * @param {Object } data
98
- * @param {Function } afterBuild
99
- * @param {Function } afterTransition
108
+ * @param {Function } [cb]
100
109
*/
101
110
102
- setComponent : function ( value , data , afterBuild , afterTransition ) {
111
+ setComponent : function ( value , cb ) {
103
112
this . invalidatePending ( )
104
113
if ( ! value ) {
105
114
// just remove current
106
115
this . unbuild ( true )
107
- this . remove ( this . childVM , afterTransition )
116
+ this . remove ( this . childVM , cb )
108
117
this . unsetCurrent ( )
109
118
} else {
110
119
this . resolveComponent ( value , _ . bind ( function ( ) {
111
120
this . unbuild ( true )
112
- var newComponent = this . build ( data )
113
- /* istanbul ignore if */
114
- if ( afterBuild ) afterBuild ( newComponent )
121
+ var options
115
122
var self = this
116
- if ( this . readyEvent ) {
117
- newComponent . $once ( this . readyEvent , function ( ) {
118
- self . transition ( newComponent , afterTransition )
119
- } )
120
- } else {
121
- this . transition ( newComponent , afterTransition )
123
+ var waitFor = this . waitForEvent
124
+ if ( waitFor ) {
125
+ options = {
126
+ created : function ( ) {
127
+ this . $once ( waitFor , function ( ) {
128
+ self . transition ( this , cb )
129
+ } )
130
+ }
131
+ }
132
+ }
133
+ var newComponent = this . build ( options )
134
+ if ( ! waitFor ) {
135
+ this . transition ( newComponent , cb )
122
136
}
123
137
} , this ) )
124
138
}
@@ -157,31 +171,35 @@ module.exports = {
157
171
* If keep alive and has cached instance, insert that
158
172
* instance; otherwise build a new one and cache it.
159
173
*
160
- * @param {Object } [data ]
174
+ * @param {Object } [extraOptions ]
161
175
* @return {Vue } - the created instance
162
176
*/
163
177
164
- build : function ( data ) {
178
+ build : function ( extraOptions ) {
165
179
if ( this . keepAlive ) {
166
180
var cached = this . cache [ this . componentID ]
167
181
if ( cached ) {
168
182
return cached
169
183
}
170
184
}
171
185
if ( this . Component ) {
172
- var parent = this . _host || this . vm
173
- var el = templateParser . clone ( this . el )
174
- var child = parent . $addChild ( {
175
- el : el ,
176
- data : data ,
186
+ // default options
187
+ var options = {
188
+ el : templateParser . clone ( this . el ) ,
177
189
template : this . template ,
178
190
// if no inline-template, then the compiled
179
191
// linker can be cached for better performance.
180
192
_linkerCachable : ! this . template ,
181
193
_asComponent : true ,
182
194
_isRouterView : this . _isRouterView ,
183
195
_context : this . vm
184
- } , this . Component )
196
+ }
197
+ // extra options
198
+ if ( extraOptions ) {
199
+ _ . extend ( options , extraOptions )
200
+ }
201
+ var parent = this . _host || this . vm
202
+ var child = parent . $addChild ( options , this . Component )
185
203
if ( this . keepAlive ) {
186
204
this . cache [ this . componentID ] = child
187
205
}
0 commit comments