Просмотр исходного кода

make transcluded components children of their host

Evan You 11 лет назад
Родитель
Сommit
2a9ff5cb7c

+ 1 - 2
src/directives/component.js

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

+ 2 - 11
src/directives/if.js

@@ -78,12 +78,6 @@ module.exports = {
     var vm = this.vm
     var start = this.start.nextSibling
     var end = this.end
-    var selfCompoents =
-      vm.$children.length &&
-      vm.$children.filter(contains)
-    var transComponents =
-      vm._transCpnts &&
-      vm._transCpnts.filter(contains)
 
     function contains (c) {
       var cur = start
@@ -101,11 +95,8 @@ module.exports = {
       return false
     }
 
-    return selfCompoents
-      ? transComponents
-        ? selfCompoents.concat(transComponents)
-        : selfCompoents
-      : transComponents
+    return vm.$children.length &&
+      vm.$children.filter(contains)
   },
 
   unbind: function () {

+ 2 - 3
src/directives/repeat.js

@@ -346,7 +346,8 @@ module.exports = {
     }
     // resolve constructor
     var Ctor = this.Ctor || this.resolveDynamicComponent(data, meta)
-    var vm = this.vm.$addChild({
+    var owner = this._host || this.vm
+    var vm = owner.$addChild({
       el: templateParser.clone(this.template),
       data: data,
       inherit: this.inherit,
@@ -359,8 +360,6 @@ module.exports = {
       _asComponent: this.asComponent,
       // linker cachable if no inline-template
       _linkerCachable: !this.inlineTemplate && Ctor !== _.Vue,
-      // transclusion host
-      _host: this._host,
       // pre-compiled linker for simple repeats
       _linkFn: this._linkFn,
       // identifier, shows that this vm belongs to this collection

+ 0 - 6
src/instance/compile.js

@@ -129,11 +129,6 @@ exports._destroy = function (remove, deferCleanup) {
   if (parent && !parent._isBeingDestroyed) {
     parent.$children.$remove(this)
   }
-  // same for transclusion host.
-  var host = this._host
-  if (host && !host._isBeingDestroyed) {
-    host._transCpnts.$remove(this)
-  }
   // destroy all children.
   i = this.$children.length
   while (i--) {
@@ -182,7 +177,6 @@ exports._cleanup = function () {
   this.$parent =
   this.$root =
   this.$children =
-  this._transCpnts =
   this._directives = null
   // call the last hook...
   this._isDestroyed = true

+ 0 - 6
src/instance/events.js

@@ -80,9 +80,6 @@ exports._initDOMHooks = function () {
 function onAttached () {
   this._isAttached = true
   this.$children.forEach(callAttach)
-  if (this._transCpnts.length) {
-    this._transCpnts.forEach(callAttach)
-  }
 }
 
 /**
@@ -104,9 +101,6 @@ function callAttach (child) {
 function onDetached () {
   this._isAttached = false
   this.$children.forEach(callDetach)
-  if (this._transCpnts.length) {
-    this._transCpnts.forEach(callDetach)
-  }
 }
 
 /**

+ 0 - 9
src/instance/init.js

@@ -48,19 +48,10 @@ exports._init = function (options) {
   this.$children = []
   this._childCtors = {}
 
-  // transcluded components that belong to the parent.
-  // need to keep track of them so that we can call
-  // attached/detached hooks on them.
-  this._transCpnts = []
-  this._host = options._host
-
   // push self into parent / transclusion host
   if (this.$parent) {
     this.$parent.$children.push(this)
   }
-  if (this._host) {
-    this._host._transCpnts.push(this)
-  }
 
   // props used in v-repeat diffing
   this._reused = false