@@ -28,7 +28,7 @@ module.exports = {
2828 // cache object, with its constructor id as the key.
2929 this . keepAlive = this . _checkParam ( 'keep-alive' ) != null
3030 // wait for event before insertion
31- this . readyEvent = this . _checkParam ( 'wait-for' )
31+ this . waitForEvent = this . _checkParam ( 'wait-for' )
3232 // check ref
3333 this . refID = this . _checkParam ( config . prefix + 'ref' )
3434 if ( this . keepAlive ) {
@@ -66,15 +66,23 @@ module.exports = {
6666 */
6767
6868 initStatic : function ( ) {
69- var child = this . build ( )
69+ // wait-for
7070 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 )
7183 this . setCurrent ( child )
72- if ( ! this . readyEvent ) {
84+ if ( ! this . waitForEvent ) {
7385 child . $before ( anchor )
74- } else {
75- child . $once ( this . readyEvent , function ( ) {
76- child . $before ( anchor )
77- } )
7886 }
7987 } ,
8088
@@ -93,32 +101,38 @@ module.exports = {
93101 * specified transition mode. Accepts a few additional
94102 * arguments specifically for vue-router.
95103 *
104+ * The callback is called when the full transition is
105+ * finished.
106+ *
96107 * @param {String } value
97- * @param {Object } data
98- * @param {Function } afterBuild
99- * @param {Function } afterTransition
108+ * @param {Function } [cb]
100109 */
101110
102- setComponent : function ( value , data , afterBuild , afterTransition ) {
111+ setComponent : function ( value , cb ) {
103112 this . invalidatePending ( )
104113 if ( ! value ) {
105114 // just remove current
106115 this . unbuild ( true )
107- this . remove ( this . childVM , afterTransition )
116+ this . remove ( this . childVM , cb )
108117 this . unsetCurrent ( )
109118 } else {
110119 this . resolveComponent ( value , _ . bind ( function ( ) {
111120 this . unbuild ( true )
112- var newComponent = this . build ( data )
113- /* istanbul ignore if */
114- if ( afterBuild ) afterBuild ( newComponent )
121+ var options
115122 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 )
122136 }
123137 } , this ) )
124138 }
@@ -157,31 +171,35 @@ module.exports = {
157171 * If keep alive and has cached instance, insert that
158172 * instance; otherwise build a new one and cache it.
159173 *
160- * @param {Object } [data ]
174+ * @param {Object } [extraOptions ]
161175 * @return {Vue } - the created instance
162176 */
163177
164- build : function ( data ) {
178+ build : function ( extraOptions ) {
165179 if ( this . keepAlive ) {
166180 var cached = this . cache [ this . componentID ]
167181 if ( cached ) {
168182 return cached
169183 }
170184 }
171185 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 ) ,
177189 template : this . template ,
178190 // if no inline-template, then the compiled
179191 // linker can be cached for better performance.
180192 _linkerCachable : ! this . template ,
181193 _asComponent : true ,
182194 _isRouterView : this . _isRouterView ,
183195 _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 )
185203 if ( this . keepAlive ) {
186204 this . cache [ this . componentID ] = child
187205 }
0 commit comments