File tree 2 files changed +38
-0
lines changed
test/unit/specs/directives
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ module.exports = {
53
53
; ( this . contentPositions = this . contentPositions || [ ] ) . push ( i )
54
54
}
55
55
}
56
+ // keep track of any transcluded components contained within
57
+ // the conditional block. we need to call attach/detach hooks
58
+ // for them.
59
+ this . transCpnts =
60
+ this . vm . _transCpnts &&
61
+ this . vm . _transCpnts . filter ( function ( c ) {
62
+ return el . contains ( c . $el )
63
+ } )
56
64
} ,
57
65
58
66
update : function ( value ) {
@@ -87,6 +95,9 @@ module.exports = {
87
95
: vm . $compile ( frag )
88
96
transition . blockAppend ( frag , this . end , vm )
89
97
this . children = vm . _children . slice ( originalChildLength )
98
+ if ( this . transCpnts ) {
99
+ this . children = this . children . concat ( this . transCpnts )
100
+ }
90
101
if ( this . children . length && _ . inDoc ( vm . $el ) ) {
91
102
this . children . forEach ( function ( child ) {
92
103
child . _callHook ( 'attached' )
Original file line number Diff line number Diff line change @@ -212,5 +212,32 @@ if (_.inBrowser) {
212
212
} )
213
213
} )
214
214
215
+ it ( 'call attach/detach for transcluded components' , function ( done ) {
216
+ document . body . appendChild ( el )
217
+ var attachSpy = jasmine . createSpy ( 'attached' )
218
+ var detachSpy = jasmine . createSpy ( 'detached' )
219
+ var vm = new Vue ( {
220
+ el : el ,
221
+ data : { show : true } ,
222
+ template : '<div v-component="outer"><div v-component="transcluded"></div></div>' ,
223
+ components : {
224
+ outer : {
225
+ template : '<div v-if="$parent.show"><content></content></div>'
226
+ } ,
227
+ transcluded : {
228
+ template : 'transcluded' ,
229
+ attached : attachSpy ,
230
+ detached : detachSpy
231
+ }
232
+ }
233
+ } )
234
+ expect ( attachSpy ) . toHaveBeenCalled ( )
235
+ vm . show = false
236
+ _ . nextTick ( function ( ) {
237
+ expect ( detachSpy ) . toHaveBeenCalled ( )
238
+ done ( )
239
+ } )
240
+ } )
241
+
215
242
} )
216
243
}
You can’t perform that action at this time.
0 commit comments