ソースを参照

optimize v-repeat with component using new transclude logic

Evan You 11 年 前
コミット
1166f8736f
2 ファイル変更9 行追加15 行削除
  1. 1 0
      src/compiler/transclude.js
  2. 8 15
      src/directives/repeat.js

+ 1 - 0
src/compiler/transclude.js

@@ -188,6 +188,7 @@ function insertContentAt (outlet, contents) {
  */
 
 function extractAttrs (attrs) {
+  if (!attrs) return null
   var res = {}
   var vwith = config.prefix + 'with'
   var i = attrs.length

+ 8 - 15
src/directives/repeat.js

@@ -107,21 +107,14 @@ module.exports = {
       if (!tokens) { // static component
         var Ctor = this.Ctor = options.components[id]
         _.assertAsset(Ctor, 'component', id)
-        // If there's no parent scope directives and no
-        // content to be transcluded, we can optimize the
-        // rendering by pre-transcluding + compiling here
-        // and provide a link function to every instance.
-        if (!this.el.hasChildNodes() &&
-            !this.el.hasAttributes()) {
-          // merge an empty object with owner vm as parent
-          // so child vms can access parent assets.
-          var merged = mergeOptions(Ctor.options, {}, {
-            $parent: this.vm
-          })
-          merged.template = this.inlineTempalte || merged.template
-          this.template = transclude(this.template, merged)
-          this._linkFn = compile(this.template, merged)
-        }
+        var merged = mergeOptions(Ctor.options, {}, {
+          $parent: this.vm
+        })
+        merged.template = this.inlineTempalte || merged.template
+        merged._asComponent = true
+        merged._parent = this.vm
+        this.template = transclude(this.template, merged)
+        this._linkFn = compile(this.template, merged)
       } else {
         // to be resolved later
         var ctorExp = textParser.tokensToExp(tokens)