Skip to content

Commit 2a9ff5c

Browse files
committed
make transcluded components children of their host
1 parent 850a7e7 commit 2a9ff5c

File tree

6 files changed

+5
-37
lines changed

6 files changed

+5
-37
lines changed

src/directives/component.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ module.exports = {
166166
return cached
167167
}
168168
}
169-
var vm = this.vm
169+
var vm = this._host || this.vm
170170
var el = templateParser.clone(this.el)
171171
if (this.Ctor) {
172172
var child = vm.$addChild({
@@ -177,7 +177,6 @@ module.exports = {
177177
// linker can be cached for better performance.
178178
_linkerCachable: !this.template,
179179
_asComponent: true,
180-
_host: this._host,
181180
_isRouterView: this._isRouterView
182181
}, this.Ctor)
183182
if (this.keepAlive) {

src/directives/if.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ module.exports = {
7878
var vm = this.vm
7979
var start = this.start.nextSibling
8080
var end = this.end
81-
var selfCompoents =
82-
vm.$children.length &&
83-
vm.$children.filter(contains)
84-
var transComponents =
85-
vm._transCpnts &&
86-
vm._transCpnts.filter(contains)
8781

8882
function contains (c) {
8983
var cur = start
@@ -101,11 +95,8 @@ module.exports = {
10195
return false
10296
}
10397

104-
return selfCompoents
105-
? transComponents
106-
? selfCompoents.concat(transComponents)
107-
: selfCompoents
108-
: transComponents
98+
return vm.$children.length &&
99+
vm.$children.filter(contains)
109100
},
110101

111102
unbind: function () {

src/directives/repeat.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ module.exports = {
346346
}
347347
// resolve constructor
348348
var Ctor = this.Ctor || this.resolveDynamicComponent(data, meta)
349-
var vm = this.vm.$addChild({
349+
var owner = this._host || this.vm
350+
var vm = owner.$addChild({
350351
el: templateParser.clone(this.template),
351352
data: data,
352353
inherit: this.inherit,
@@ -359,8 +360,6 @@ module.exports = {
359360
_asComponent: this.asComponent,
360361
// linker cachable if no inline-template
361362
_linkerCachable: !this.inlineTemplate && Ctor !== _.Vue,
362-
// transclusion host
363-
_host: this._host,
364363
// pre-compiled linker for simple repeats
365364
_linkFn: this._linkFn,
366365
// identifier, shows that this vm belongs to this collection

src/instance/compile.js

-6
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ exports._destroy = function (remove, deferCleanup) {
129129
if (parent && !parent._isBeingDestroyed) {
130130
parent.$children.$remove(this)
131131
}
132-
// same for transclusion host.
133-
var host = this._host
134-
if (host && !host._isBeingDestroyed) {
135-
host._transCpnts.$remove(this)
136-
}
137132
// destroy all children.
138133
i = this.$children.length
139134
while (i--) {
@@ -182,7 +177,6 @@ exports._cleanup = function () {
182177
this.$parent =
183178
this.$root =
184179
this.$children =
185-
this._transCpnts =
186180
this._directives = null
187181
// call the last hook...
188182
this._isDestroyed = true

src/instance/events.js

-6
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ exports._initDOMHooks = function () {
8080
function onAttached () {
8181
this._isAttached = true
8282
this.$children.forEach(callAttach)
83-
if (this._transCpnts.length) {
84-
this._transCpnts.forEach(callAttach)
85-
}
8683
}
8784

8885
/**
@@ -104,9 +101,6 @@ function callAttach (child) {
104101
function onDetached () {
105102
this._isAttached = false
106103
this.$children.forEach(callDetach)
107-
if (this._transCpnts.length) {
108-
this._transCpnts.forEach(callDetach)
109-
}
110104
}
111105

112106
/**

src/instance/init.js

-9
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,10 @@ exports._init = function (options) {
4848
this.$children = []
4949
this._childCtors = {}
5050

51-
// transcluded components that belong to the parent.
52-
// need to keep track of them so that we can call
53-
// attached/detached hooks on them.
54-
this._transCpnts = []
55-
this._host = options._host
56-
5751
// push self into parent / transclusion host
5852
if (this.$parent) {
5953
this.$parent.$children.push(this)
6054
}
61-
if (this._host) {
62-
this._host._transCpnts.push(this)
63-
}
6455

6556
// props used in v-repeat diffing
6657
this._reused = false

0 commit comments

Comments
 (0)