Skip to content

Commit cbc402a

Browse files
committed
make nested transclusions test pass
1 parent 2a9ff5c commit cbc402a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/directives/component.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,19 @@ module.exports = {
166166
return cached
167167
}
168168
}
169-
var vm = this._host || this.vm
169+
var owner = this._host || this.vm
170170
var el = templateParser.clone(this.el)
171171
if (this.Ctor) {
172-
var child = vm.$addChild({
172+
var child = owner.$addChild({
173173
el: el,
174174
data: data,
175175
template: this.template,
176176
// if no inline-template, then the compiled
177177
// linker can be cached for better performance.
178178
_linkerCachable: !this.template,
179179
_asComponent: true,
180-
_isRouterView: this._isRouterView
180+
_isRouterView: this._isRouterView,
181+
_contentOwner: this.vm
181182
}, this.Ctor)
182183
if (this.keepAlive) {
183184
this.cache[this.ctorId] = child

src/directives/repeat.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ module.exports = {
363363
// pre-compiled linker for simple repeats
364364
_linkFn: this._linkFn,
365365
// identifier, shows that this vm belongs to this collection
366-
_repeatId: this.id
366+
_repeatId: this.id,
367+
// transclusion content owner
368+
_contentOwner: this.vm
367369
}, Ctor)
368370
// cache instance
369371
if (needCache) {

src/element-directives/content.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,38 @@ module.exports = {
99

1010
bind: function () {
1111
var vm = this.vm
12-
var contentOwner = vm
12+
var host = vm
1313
// we need find the content owner, which is the closest
1414
// non-inline-repeater instance.
15-
while (contentOwner.$options._repeat) {
16-
contentOwner = contentOwner.$parent
15+
while (host.$options._repeat) {
16+
host = host.$parent
1717
}
18-
var raw = contentOwner.$options._content
18+
var raw = host.$options._content
1919
var content
2020
if (!raw) {
2121
this.fallback()
2222
return
2323
}
24-
var parent = contentOwner.$parent
24+
var owner =
25+
host.$options._contentOwner ||
26+
host.$parent
2527
var selector = this.el.getAttribute('select')
2628
if (!selector) {
2729
// Default content
2830
var self = this
2931
var compileDefaultContent = function () {
3032
self.compile(
3133
extractFragment(raw.childNodes, raw, true),
32-
contentOwner.$parent,
34+
owner,
3335
vm
3436
)
3537
}
36-
if (!contentOwner._isCompiled) {
38+
if (!host._isCompiled) {
3739
// defer until the end of instance compilation,
3840
// because the default outlet must wait until all
3941
// other possible outlets with selectors have picked
4042
// out their contents.
41-
contentOwner.$once('hook:compiled', compileDefaultContent)
43+
host.$once('hook:compiled', compileDefaultContent)
4244
} else {
4345
compileDefaultContent()
4446
}
@@ -49,7 +51,7 @@ module.exports = {
4951
if (nodes.length) {
5052
content = extractFragment(nodes, raw)
5153
if (content.hasChildNodes()) {
52-
this.compile(content, parent, vm)
54+
this.compile(content, owner, vm)
5355
} else {
5456
this.fallback()
5557
}

0 commit comments

Comments
 (0)