@@ -50,46 +50,81 @@ module.exports = {
5050 // NOTE: this function is shared in v-partial
5151 compile : function ( frag ) {
5252 var vm = this . vm
53- var originalChildLength = vm . _children . length
54- var originalParentChildLength = vm . $parent &&
55- vm . $parent . _children . length
5653 // the linker is not guaranteed to be present because
5754 // this function might get called by v-partial
5855 this . unlink = this . linker
5956 ? this . linker ( vm , frag )
6057 : vm . $compile ( frag )
6158 transition . blockAppend ( frag , this . end , vm )
62- this . children = vm . _children . slice ( originalChildLength )
63- if ( vm . $parent ) {
64- this . children = this . children . concat (
65- vm . $parent . _children . slice ( originalParentChildLength )
66- )
67- }
68- if ( this . children . length && _ . inDoc ( vm . $el ) ) {
69- this . children . forEach ( function ( child ) {
70- child . _callHook ( 'attached' )
71- } )
59+ // call attached for all the child components created
60+ // during the compilation
61+ if ( _ . inDoc ( vm . $el ) ) {
62+ var children = this . getContainedComponents ( )
63+ if ( children ) children . forEach ( callAttach )
7264 }
7365 } ,
7466
7567 // NOTE: this function is shared in v-partial
7668 teardown : function ( ) {
7769 if ( ! this . unlink ) return
78- transition . blockRemove ( this . start , this . end , this . vm )
79- if ( this . children && _ . inDoc ( this . vm . $el ) ) {
80- this . children . forEach ( function ( child ) {
81- if ( ! child . _isDestroyed ) {
82- child . _callHook ( 'detached' )
83- }
84- } )
70+ // collect children beforehand
71+ var children
72+ if ( _ . inDoc ( this . vm . $el ) ) {
73+ children = this . getContainedComponents ( )
8574 }
75+ transition . blockRemove ( this . start , this . end , this . vm )
76+ if ( children ) children . forEach ( callDetach )
8677 this . unlink ( )
8778 this . unlink = null
8879 } ,
8980
81+ // NOTE: this function is shared in v-partial
82+ getContainedComponents : function ( ) {
83+ var vm = this . vm
84+ var start = this . start . nextSibling
85+ var end = this . end
86+ var selfCompoents =
87+ vm . _children . length &&
88+ vm . _children . filter ( contains )
89+ var transComponents =
90+ vm . _transCpnts &&
91+ vm . _transCpnts . filter ( contains )
92+
93+ function contains ( c ) {
94+ var cur = start
95+ var next
96+ while ( next !== end ) {
97+ next = cur . nextSibling
98+ if ( cur . contains ( c . $el ) ) {
99+ return true
100+ }
101+ cur = next
102+ }
103+ return false
104+ }
105+
106+ return selfCompoents
107+ ? transComponents
108+ ? selfCompoents . concat ( transComponents )
109+ : selfCompoents
110+ : transComponents
111+ } ,
112+
90113 // NOTE: this function is shared in v-partial
91114 unbind : function ( ) {
92115 if ( this . unlink ) this . unlink ( )
93116 }
94117
118+ }
119+
120+ function callAttach ( child ) {
121+ if ( ! child . _isAttached ) {
122+ child . _callHook ( 'attached' )
123+ }
124+ }
125+
126+ function callDetach ( child ) {
127+ if ( child . _isAttached ) {
128+ child . _callHook ( 'detached' )
129+ }
95130}
0 commit comments