瀏覽代碼

change block instance strategy

Evan You 11 年之前
父節點
當前提交
ea067d4275
共有 5 個文件被更改,包括 10 次插入11 次删除
  1. 2 1
      .jshintrc
  2. 2 2
      src/instance/compile.js
  3. 5 5
      src/instance/element.js
  4. 1 1
      src/instance/init.js
  5. 0 2
      src/parse/template.js

+ 2 - 1
.jshintrc

@@ -13,6 +13,7 @@
   "eqnull": true,
   "proto": true,
   "globals": {
-    "console": true
+    "console": true,
+    "DocumentFragment": true
   }
 }

+ 2 - 2
src/instance/compile.js

@@ -8,8 +8,8 @@ var config = require('../config')
  */
 
 exports._compile = function () {
-  if (this._isBlock) {
-    this.$el.forEach(this._compileNode, this)
+  if (this._blockNodes) {
+    this._blockNodes.forEach(this._compileNode, this)
   } else {
     this._compileNode(this.$el)
   }

+ 5 - 5
src/instance/element.js

@@ -22,9 +22,9 @@ exports._initElement = function (el) {
   // instance is considered a "block instance" which manages
   // not a single element, but multiple elements. A block
   // instance's `$el` is an Array of the elements it manages.
-  if (el instanceof window.DocumentFragment) {
-    this._isBlock = true
-    this.$el = _.toArray(el.childNodes)
+  if (el instanceof DocumentFragment) {
+    this._blockNodes = _.toArray(el.childNodes)
+    this.$el = document.createComment('vue-block')
   } else {
     this.$el = el
   }
@@ -55,8 +55,8 @@ exports._initTemplate = function () {
           // the template contains multiple nodes
           // in this case the original `el` is simply
           // a placeholder.
-          this._isBlock = true
-          this.$el = _.toArray(frag.childNodes)
+          this._blockNodes = _.toArray(frag.childNodes)
+          this.$el = document.createComment('vue-block')
         } else {
           // 1 to 1 replace, we need to copy all the
           // attributes from the original el to the replacer

+ 1 - 1
src/instance/init.js

@@ -18,7 +18,7 @@ exports._init = function (options) {
 
   this.$el          = null
   this._data        = options.data || {}
-  this._isBlock     = false
+  this._blockNodes  = null
   this._isDestroyed = false
   this._rawContent  = null
   this._emitter     = new Emitter(this)

+ 0 - 2
src/parse/template.js

@@ -1,5 +1,3 @@
-/* global DocumentFragment */
-
 var Cache = require('../cache')
 var templateCache = new Cache(100)