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

rename block instance -> fragment instance

Evan You 10 лет назад
Родитель
Сommit
974c5c3a0c

+ 5 - 5
src/api/dom.js

@@ -101,7 +101,7 @@ exports.$remove = function (cb, withTransition) {
     if (cb) cb()
   }
   if (
-    this._isBlock &&
+    this._isFragment &&
     !this._blockFragment.hasChildNodes()
   ) {
     op = withTransition === false
@@ -139,7 +139,7 @@ function insert (vm, target, cb, withTransition, op1, op2) {
     !targetIsDetached &&
     !vm._isAttached &&
     !_.inDoc(vm.$el)
-  if (vm._isBlock) {
+  if (vm._isFragment) {
     blockOp(vm, target, op, cb)
   } else {
     op(vm.$el, target, vm, cb)
@@ -151,7 +151,7 @@ function insert (vm, target, cb, withTransition, op1, op2) {
 }
 
 /**
- * Execute a transition operation on a block instance,
+ * Execute a transition operation on a fragment instance,
  * iterating through all its block nodes.
  *
  * @param {Vue} vm
@@ -161,8 +161,8 @@ function insert (vm, target, cb, withTransition, op1, op2) {
  */
 
 function blockOp (vm, target, op, cb) {
-  var current = vm._blockStart
-  var end = vm._blockEnd
+  var current = vm._fragmentStart
+  var end = vm._fragmentEnd
   var next
   while (next !== end) {
     next = current.nextSibling

+ 2 - 2
src/compiler/compile.js

@@ -146,7 +146,7 @@ exports.compileAndLinkProps = function (vm, el, props) {
  * 2. attrs on the component template root node, if
  *    replace:true (child scope)
  *
- * If this is a block instance, we only need to compile 1.
+ * If this is a fragment instance, we only need to compile 1.
  *
  * This function does compile and link at the same time,
  * since root linkers can not be reused. It returns the
@@ -165,7 +165,7 @@ exports.compileAndLinkRoot = function (vm, el, options) {
   var contextLinkFn, replacerLinkFn
 
   // only need to compile other attributes for
-  // non-block instances
+  // non-fragment instances
   if (el.nodeType !== 11) {
     // for components, container and replacer need to be
     // compiled separately and linked in different scopes.

+ 2 - 2
src/compiler/transclude.js

@@ -24,7 +24,7 @@ exports.transclude = function (el, options) {
     options._containerAttrs = extractAttrs(el)
   }
   // for template tags, what we want is its content as
-  // a documentFragment (for block instances)
+  // a documentFragment (for fragment instances)
   if (_.isTemplate(el)) {
     el = templateParser.parse(el)
   }
@@ -38,7 +38,7 @@ exports.transclude = function (el, options) {
     }
   }
   if (el instanceof DocumentFragment) {
-    // anchors for block instance
+    // anchors for fragment instance
     // passing in `persist: true` to avoid them being
     // discarded by IE during template cloning
     _.prepend(_.createAnchor('v-start', true), el)

+ 1 - 1
src/directives/repeat.js

@@ -315,7 +315,7 @@ module.exports = {
       prevEl = targetPrev
         ? targetPrev._staggerCb
           ? targetPrev._staggerAnchor
-          : targetPrev._blockEnd || targetPrev.$el
+          : targetPrev._fragmentEnd || targetPrev.$el
         : start
       if (vm._reused && !vm._staggerCb) {
         currentPrev = findPrevVm(vm, start, this.id)

+ 5 - 5
src/instance/compile.js

@@ -76,12 +76,12 @@ exports._compile = function (el) {
 
 exports._initElement = function (el) {
   if (el instanceof DocumentFragment) {
-    this._isBlock = true
-    this.$el = this._blockStart = el.firstChild
-    this._blockEnd = el.lastChild
+    this._isFragment = true
+    this.$el = this._fragmentStart = el.firstChild
+    this._fragmentEnd = el.lastChild
     // set persisted text anchors to empty
-    if (this._blockStart.nodeType === 3) {
-      this._blockStart.data = this._blockEnd.data = ''
+    if (this._fragmentStart.nodeType === 3) {
+      this._fragmentStart.data = this._fragmentEnd.data = ''
     }
     this._blockFragment = el
   } else {

+ 4 - 4
src/instance/init.js

@@ -33,10 +33,10 @@ exports._init = function (options) {
   this._eventsCount = {}       // for $broadcast optimization
   this._eventCancelled = false // for event cancellation
 
-  // block instance properties
-  this._isBlock = false
-  this._blockStart =    // @type {CommentNode}
-  this._blockEnd = null // @type {CommentNode}
+  // fragment instance properties
+  this._isFragment = false
+  this._fragmentStart =    // @type {CommentNode}
+  this._fragmentEnd = null // @type {CommentNode}
 
   // lifecycle state
   this._isCompiled =

+ 1 - 1
src/util/dom.js

@@ -240,7 +240,7 @@ exports.isTemplate = function (el) {
 /**
  * Create an "anchor" for performing dom insertion/removals.
  * This is used in a number of scenarios:
- * - block instance
+ * - fragment instance
  * - v-html
  * - v-if
  * - component

+ 14 - 14
test/unit/specs/api/dom_spec.js

@@ -41,11 +41,11 @@ if (_.inBrowser) {
       it('block instance', function () {
         vm2.$appendTo(parent, spy)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[2]).toBe(vm2._blockStart)
+        expect(parent.childNodes[2]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[2]).toBe(vm2.$el)
         expect(parent.childNodes[3].tagName).toBe('P')
         expect(parent.childNodes[4].tagName).toBe('SPAN')
-        expect(parent.childNodes[5]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[5]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(1)
       })
 
@@ -67,20 +67,20 @@ if (_.inBrowser) {
       it('block instance', function () {
         vm2.$prependTo(parent, spy)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[0]).toBe(vm2._blockStart)
+        expect(parent.childNodes[0]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[0]).toBe(vm2.$el)
         expect(parent.childNodes[1].tagName).toBe('P')
         expect(parent.childNodes[2].tagName).toBe('SPAN')
-        expect(parent.childNodes[3]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[3]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(1)
         // empty
         vm2.$prependTo(empty, spy)
         expect(empty.childNodes.length).toBe(4)
-        expect(empty.childNodes[0]).toBe(vm2._blockStart)
+        expect(empty.childNodes[0]).toBe(vm2._fragmentStart)
         expect(empty.childNodes[0]).toBe(vm2.$el)
         expect(empty.childNodes[1].tagName).toBe('P')
         expect(empty.childNodes[2].tagName).toBe('SPAN')
-        expect(empty.childNodes[3]).toBe(vm2._blockEnd)
+        expect(empty.childNodes[3]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(2)
       })
 
@@ -98,11 +98,11 @@ if (_.inBrowser) {
       it('block instance', function () {
         vm2.$before(sibling, spy)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[1]).toBe(vm2._blockStart)
+        expect(parent.childNodes[1]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[1]).toBe(vm2.$el)
         expect(parent.childNodes[2].tagName).toBe('P')
         expect(parent.childNodes[3].tagName).toBe('SPAN')
-        expect(parent.childNodes[4]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[4]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(1)
       })
 
@@ -127,22 +127,22 @@ if (_.inBrowser) {
       it('block instance', function () {
         vm2.$after(target, spy)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[1]).toBe(vm2._blockStart)
+        expect(parent.childNodes[1]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[1]).toBe(vm2.$el)
         expect(parent.childNodes[2].tagName).toBe('P')
         expect(parent.childNodes[3].tagName).toBe('SPAN')
-        expect(parent.childNodes[4]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[4]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(1)
       })
 
       it('block instance no next sibling', function () {
         vm2.$after(sibling, spy)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[2]).toBe(vm2._blockStart)
+        expect(parent.childNodes[2]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[2]).toBe(vm2.$el)
         expect(parent.childNodes[3].tagName).toBe('P')
         expect(parent.childNodes[4].tagName).toBe('SPAN')
-        expect(parent.childNodes[5]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[5]).toBe(vm2._fragmentEnd)
         expect(spy.calls.count()).toBe(1)
       })
 
@@ -164,11 +164,11 @@ if (_.inBrowser) {
       it('block instance', function () {
         vm2.$before(sibling)
         expect(parent.childNodes.length).toBe(6)
-        expect(parent.childNodes[1]).toBe(vm2._blockStart)
+        expect(parent.childNodes[1]).toBe(vm2._fragmentStart)
         expect(parent.childNodes[1]).toBe(vm2.$el)
         expect(parent.childNodes[2].tagName).toBe('P')
         expect(parent.childNodes[3].tagName).toBe('SPAN')
-        expect(parent.childNodes[4]).toBe(vm2._blockEnd)
+        expect(parent.childNodes[4]).toBe(vm2._fragmentEnd)
         vm2.$remove(spy)
         expect(parent.childNodes.length).toBe(2)
         expect(parent.childNodes[0]).toBe(target)

+ 1 - 1
test/unit/specs/api/lifecycle_spec.js

@@ -112,7 +112,7 @@ if (_.inBrowser) {
         expect(vm.$el.nextSibling.textContent).toBe('hi!')
         expect(vm.$el.nextSibling.nextSibling.textContent).toBe('hi!!')
         expect(document.body.contains(el)).toBe(false)
-        expect(document.body.lastChild).toBe(vm._blockEnd)
+        expect(document.body.lastChild).toBe(vm._fragmentEnd)
         vm.$remove()
       })
 

+ 1 - 1
test/unit/specs/element-directives/content_spec.js

@@ -95,7 +95,7 @@ describe('Content Transclusion', function () {
     expect(getChild(3).tagName).toBe('SPAN')
 
     function getChild (n) {
-      var el = vm._blockStart
+      var el = vm._fragmentStart
       while (n--) {
         el = el.nextSibling
       }