Skip to content

Commit 3f943c6

Browse files
committed
fix attach/detach hooks for transcluded components
1 parent 79c154f commit 3f943c6

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/instance/compile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ exports._compile = function (el) {
3939
parentOptions._skipAttrs = null
4040

4141
if (content) {
42+
var ol = parent._children.length
4243
var contentLinkFn =
4344
compile(content, parentOptions, true)
4445
// call content linker now, before transclusion
4546
this._contentUnlinkFn = contentLinkFn(parent, content)
47+
this._transCpnts = parent._children.slice(ol)
4648
}
4749
// tranclude, this possibly replaces original
4850
el = transclude(el, options)
@@ -176,6 +178,7 @@ exports._cleanup = function () {
176178
this.$parent =
177179
this.$root =
178180
this._children =
181+
this._transCpnts =
179182
this._directives = null
180183
// call the last hook...
181184
this._isDestroyed = true

src/instance/events.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,21 @@ exports._initDOMHooks = function () {
7979

8080
function onAttached () {
8181
this._isAttached = true
82-
var children = this._children
83-
for (var i = 0, l = children.length; i < l; i++) {
84-
var child = children[i]
85-
if (!child._isAttached && inDoc(child.$el)) {
86-
child._callHook('attached')
87-
}
82+
this._children.forEach(callAttach)
83+
if (this._transCpnts) {
84+
this._transCpnts.forEach(callAttach)
85+
}
86+
}
87+
88+
/**
89+
* Iterator to call attached hook
90+
*
91+
* @param {Vue} child
92+
*/
93+
94+
function callAttach (child) {
95+
if (!child._isAttached && inDoc(child.$el)) {
96+
child._callHook('attached')
8897
}
8998
}
9099

@@ -94,12 +103,21 @@ function onAttached () {
94103

95104
function onDetached () {
96105
this._isAttached = false
97-
var children = this._children
98-
for (var i = 0, l = children.length; i < l; i++) {
99-
var child = children[i]
100-
if (child._isAttached && !inDoc(child.$el)) {
101-
child._callHook('detached')
102-
}
106+
this._children.forEach(callDetach)
107+
if (this._transCpnts) {
108+
this._transCpnts.forEach(callDetach)
109+
}
110+
}
111+
112+
/**
113+
* Iterator to call detached hook
114+
*
115+
* @param {Vue} child
116+
*/
117+
118+
function callDetach (child) {
119+
if (child._isAttached && !inDoc(child.$el)) {
120+
child._callHook('detached')
103121
}
104122
}
105123

src/instance/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ exports._init = function (options) {
4848
// children
4949
this._children = []
5050
this._childCtors = {}
51+
// transcluded components that belong to the parent
52+
this._transCpnts = null
5153

5254
// merge options.
5355
options = this.$options = mergeOptions(

0 commit comments

Comments
 (0)