File tree Expand file tree Collapse file tree 3 files changed +55
-4
lines changed
test/unit/specs/directives/internal Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -139,12 +139,12 @@ export default {
139
139
// actual mount
140
140
this . unbuild ( true )
141
141
var self = this
142
- var activateHook = this . Component . options . activate
142
+ var activateHooks = this . Component . options . activate
143
143
var cached = this . getCached ( )
144
144
var newComponent = this . build ( )
145
- if ( activateHook && ! cached ) {
145
+ if ( activateHooks && ! cached ) {
146
146
this . waitingFor = newComponent
147
- activateHook . call ( newComponent , function ( ) {
147
+ callActivateHooks ( activateHooks , newComponent , function ( ) {
148
148
if ( self . waitingFor !== newComponent ) {
149
149
return
150
150
}
@@ -358,3 +358,24 @@ export default {
358
358
}
359
359
}
360
360
}
361
+
362
+ /**
363
+ * Call activate hooks in order (asynchronous)
364
+ *
365
+ * @param {Array } hooks
366
+ * @param {Vue } vm
367
+ * @param {Function } cb
368
+ */
369
+
370
+ function callActivateHooks ( hooks , vm , cb ) {
371
+ var total = hooks . length
372
+ var called = 0
373
+ hooks [ 0 ] . call ( vm , next )
374
+ function next ( ) {
375
+ if ( ++ called >= total ) {
376
+ cb ( )
377
+ } else {
378
+ hooks [ called ] . call ( vm , next )
379
+ }
380
+ }
381
+ }
Original file line number Diff line number Diff line change @@ -126,7 +126,8 @@ strats.detached =
126
126
strats . beforeCompile =
127
127
strats . compiled =
128
128
strats . beforeDestroy =
129
- strats . destroyed = function ( parentVal , childVal ) {
129
+ strats . destroyed =
130
+ strats . activate = function ( parentVal , childVal ) {
130
131
return childVal
131
132
? parentVal
132
133
? parentVal . concat ( childVal )
Original file line number Diff line number Diff line change @@ -282,6 +282,35 @@ describe('Component', function () {
282
282
} )
283
283
} )
284
284
285
+ it ( 'multiple activate hooks' , function ( done ) {
286
+ var mixinSpy = jasmine . createSpy ( 'mixin activate' )
287
+ new Vue ( {
288
+ el : el ,
289
+ template : '<view-a></view-a>' ,
290
+ components : {
291
+ 'view-a' : {
292
+ template : 'AAA' ,
293
+ mixins : [ {
294
+ activate : function ( done ) {
295
+ expect ( el . textContent ) . toBe ( '' )
296
+ mixinSpy ( )
297
+ done ( )
298
+ }
299
+ } ] ,
300
+ activate : function ( ready ) {
301
+ setTimeout ( function ( ) {
302
+ expect ( mixinSpy ) . toHaveBeenCalled ( )
303
+ expect ( el . textContent ) . toBe ( '' )
304
+ ready ( )
305
+ expect ( el . textContent ) . toBe ( 'AAA' )
306
+ done ( )
307
+ } , 0 )
308
+ }
309
+ }
310
+ }
311
+ } )
312
+ } )
313
+
285
314
it ( 'activate hook for dynamic components' , function ( done ) {
286
315
var next
287
316
var vm = new Vue ( {
You can’t perform that action at this time.
0 commit comments