Răsfoiți Sursa

make nested transclusions test pass

Evan You 11 ani în urmă
părinte
comite
cbc402a35f
3 a modificat fișierele cu 18 adăugiri și 13 ștergeri
  1. 4 3
      src/directives/component.js
  2. 3 1
      src/directives/repeat.js
  3. 11 9
      src/element-directives/content.js

+ 4 - 3
src/directives/component.js

@@ -166,10 +166,10 @@ module.exports = {
         return cached
       }
     }
-    var vm = this._host || this.vm
+    var owner = this._host || this.vm
     var el = templateParser.clone(this.el)
     if (this.Ctor) {
-      var child = vm.$addChild({
+      var child = owner.$addChild({
         el: el,
         data: data,
         template: this.template,
@@ -177,7 +177,8 @@ module.exports = {
         // linker can be cached for better performance.
         _linkerCachable: !this.template,
         _asComponent: true,
-        _isRouterView: this._isRouterView
+        _isRouterView: this._isRouterView,
+        _contentOwner: this.vm
       }, this.Ctor)
       if (this.keepAlive) {
         this.cache[this.ctorId] = child

+ 3 - 1
src/directives/repeat.js

@@ -363,7 +363,9 @@ module.exports = {
       // pre-compiled linker for simple repeats
       _linkFn: this._linkFn,
       // identifier, shows that this vm belongs to this collection
-      _repeatId: this.id
+      _repeatId: this.id,
+      // transclusion content owner
+      _contentOwner: this.vm
     }, Ctor)
     // cache instance
     if (needCache) {

+ 11 - 9
src/element-directives/content.js

@@ -9,19 +9,21 @@ module.exports = {
 
   bind: function () {
     var vm = this.vm
-    var contentOwner = vm
+    var host = vm
     // we need find the content owner, which is the closest
     // non-inline-repeater instance.
-    while (contentOwner.$options._repeat) {
-      contentOwner = contentOwner.$parent
+    while (host.$options._repeat) {
+      host = host.$parent
     }
-    var raw = contentOwner.$options._content
+    var raw = host.$options._content
     var content
     if (!raw) {
       this.fallback()
       return
     }
-    var parent = contentOwner.$parent
+    var owner =
+      host.$options._contentOwner ||
+      host.$parent
     var selector = this.el.getAttribute('select')
     if (!selector) {
       // Default content
@@ -29,16 +31,16 @@ module.exports = {
       var compileDefaultContent = function () {
         self.compile(
           extractFragment(raw.childNodes, raw, true),
-          contentOwner.$parent,
+          owner,
           vm
         )
       }
-      if (!contentOwner._isCompiled) {
+      if (!host._isCompiled) {
         // defer until the end of instance compilation,
         // because the default outlet must wait until all
         // other possible outlets with selectors have picked
         // out their contents.
-        contentOwner.$once('hook:compiled', compileDefaultContent)
+        host.$once('hook:compiled', compileDefaultContent)
       } else {
         compileDefaultContent()
       }
@@ -49,7 +51,7 @@ module.exports = {
       if (nodes.length) {
         content = extractFragment(nodes, raw)
         if (content.hasChildNodes()) {
-          this.compile(content, parent, vm)
+          this.compile(content, owner, vm)
         } else {
           this.fallback()
         }