Quellcode durchsuchen

_children -> $children

Evan You vor 11 Jahren
Ursprung
Commit
850a7e779b

+ 2 - 2
src/api/events.js

@@ -121,7 +121,7 @@ exports.$broadcast = function (event) {
   // if no child has registered for this event,
   // then there's no need to broadcast.
   if (!this._eventsCount[event]) return
-  var children = this._children
+  var children = this.$children
   for (var i = 0, l = children.length; i < l; i++) {
     var child = children[i]
     child.$emit.apply(child, arguments)
@@ -171,4 +171,4 @@ function modifyListenerCount (vm, event, count) {
       (parent._eventsCount[event] || 0) + count
     parent = parent.$parent
   }
-}
+}

+ 2 - 2
src/directives/if.js

@@ -79,8 +79,8 @@ module.exports = {
     var start = this.start.nextSibling
     var end = this.end
     var selfCompoents =
-      vm._children.length &&
-      vm._children.filter(contains)
+      vm.$children.length &&
+      vm.$children.filter(contains)
     var transComponents =
       vm._transCpnts &&
       vm._transCpnts.filter(contains)

+ 4 - 4
src/instance/compile.js

@@ -127,7 +127,7 @@ exports._destroy = function (remove, deferCleanup) {
   // if parent is not being destroyed as well.
   var parent = this.$parent
   if (parent && !parent._isBeingDestroyed) {
-    parent._children.$remove(this)
+    parent.$children.$remove(this)
   }
   // same for transclusion host.
   var host = this._host
@@ -135,9 +135,9 @@ exports._destroy = function (remove, deferCleanup) {
     host._transCpnts.$remove(this)
   }
   // destroy all children.
-  i = this._children.length
+  i = this.$children.length
   while (i--) {
-    this._children[i].$destroy()
+    this.$children[i].$destroy()
   }
   // teardown props
   if (this._propsUnlinkFn) {
@@ -181,7 +181,7 @@ exports._cleanup = function () {
   this.$el =
   this.$parent =
   this.$root =
-  this._children =
+  this.$children =
   this._transCpnts =
   this._directives = null
   // call the last hook...

+ 3 - 3
src/instance/events.js

@@ -79,7 +79,7 @@ exports._initDOMHooks = function () {
 
 function onAttached () {
   this._isAttached = true
-  this._children.forEach(callAttach)
+  this.$children.forEach(callAttach)
   if (this._transCpnts.length) {
     this._transCpnts.forEach(callAttach)
   }
@@ -103,7 +103,7 @@ function callAttach (child) {
 
 function onDetached () {
   this._isAttached = false
-  this._children.forEach(callDetach)
+  this.$children.forEach(callDetach)
   if (this._transCpnts.length) {
     this._transCpnts.forEach(callDetach)
   }
@@ -135,4 +135,4 @@ exports._callHook = function (hook) {
     }
   }
   this.$emit('hook:' + hook)
-}
+}

+ 2 - 2
src/instance/init.js

@@ -45,7 +45,7 @@ exports._init = function (options) {
   this._unlinkFn    = null
 
   // children
-  this._children = []
+  this.$children = []
   this._childCtors = {}
 
   // transcluded components that belong to the parent.
@@ -56,7 +56,7 @@ exports._init = function (options) {
 
   // push self into parent / transclusion host
   if (this.$parent) {
-    this.$parent._children.push(this)
+    this.$parent.$children.push(this)
   }
   if (this._host) {
     this._host._transCpnts.push(this)

+ 1 - 1
src/instance/scope.js

@@ -168,7 +168,7 @@ exports._digest = function () {
   while (i--) {
     this._watchers[i].update()
   }
-  var children = this._children
+  var children = this.$children
   i = children.length
   while (i--) {
     var child = children[i]

+ 2 - 2
test/unit/specs/api/child_spec.js

@@ -22,7 +22,7 @@ describe('Child API', function () {
     expect(child.a).toBeUndefined()
     expect(child.$parent).toBe(vm)
     expect(child.$root).toBe(vm)
-    expect(vm._children.indexOf(child)).toBe(0)
+    expect(vm.$children.indexOf(child)).toBe(0)
     expect(_.resolveAsset(child.$options, 'directives', 'test')).toBeTruthy()
   })
 
@@ -76,4 +76,4 @@ describe('Child API', function () {
     expect(child.constructor.toString().match(/^function VueTest\s?\(/)).toBeTruthy()
   })
 
-})
+})

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

@@ -164,7 +164,7 @@ if (_.inBrowser) {
         expect(vm.$el).toBeNull()
         expect(vm.$parent).toBeNull()
         expect(vm.$root).toBeNull()
-        expect(vm._children).toBeNull()
+        expect(vm.$children).toBeNull()
         expect(vm._directives).toBeNull()
         expect(Object.keys(vm._events).length).toBe(0)
       })
@@ -198,11 +198,11 @@ if (_.inBrowser) {
         var parent = new Vue()
         var child = parent.$addChild()
         var child2 = parent.$addChild()
-        expect(parent._children.length).toBe(2)
+        expect(parent.$children.length).toBe(2)
         child.$destroy()
-        expect(parent._children.length).toBe(1)
+        expect(parent.$children.length).toBe(1)
         child2.$destroy()
-        expect(parent._children.length).toBe(0)
+        expect(parent.$children.length).toBe(0)
       })
 
       it('children', function () {
@@ -300,4 +300,4 @@ if (_.inBrowser) {
     })
 
   })
-}
+}

+ 10 - 10
test/unit/specs/compiler/compile_spec.js

@@ -308,9 +308,9 @@ if (_.inBrowser) {
           }
         }
       })
-      var dirs = vm._children[0]._directives
+      var dirs = vm.$children[0]._directives
       expect(dirs.length).toBe(2)
-      vm._children[0].$destroy()
+      vm.$children[0].$destroy()
       var i = dirs.length
       while (i--) {
         expect(dirs[i]._bound).toBe(false)
@@ -333,10 +333,10 @@ if (_.inBrowser) {
       })
       expect(el.firstChild.style.display).toBe('')
       expect(vm._directives.length).toBe(2)
-      expect(vm._children.length).toBe(1)
-      vm._children[0].$destroy()
+      expect(vm.$children.length).toBe(1)
+      vm.$children[0].$destroy()
       expect(vm._directives.length).toBe(1)
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
     })
 
     it('should remove transcluded directives from parent when unlinking (component)', function () {
@@ -355,10 +355,10 @@ if (_.inBrowser) {
       })
       expect(vm.$el.textContent).toBe('parent')
       expect(vm._directives.length).toBe(2)
-      expect(vm._children.length).toBe(1)
-      vm._children[0].$destroy()
+      expect(vm.$children.length).toBe(1)
+      vm.$children[0].$destroy()
       expect(vm._directives.length).toBe(1)
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
     })
 
     it('should remove transcluded directives from parent when unlinking (v-if + component)', function (done) {
@@ -380,12 +380,12 @@ if (_.inBrowser) {
       })
       expect(vm.$el.textContent).toBe('parent')
       expect(vm._directives.length).toBe(3)
-      expect(vm._children.length).toBe(1)
+      expect(vm.$children.length).toBe(1)
       vm.ok = false
       _.nextTick(function () {
         expect(vm.$el.textContent).toBe('')
         expect(vm._directives.length).toBe(1)
-        expect(vm._children.length).toBe(0)
+        expect(vm.$children.length).toBe(0)
         done()
       })
     })

+ 9 - 9
test/unit/specs/directives/component_spec.js

@@ -234,11 +234,11 @@ if (_.inBrowser) {
         }
       })
       expect(el.textContent).toBe('')
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
       expect(vm._directives.length).toBe(1) // v-if
       vm.ok = true
       _.nextTick(function () {
-        expect(vm._children.length).toBe(1)
+        expect(vm.$children.length).toBe(1)
         expect(vm._directives.length).toBe(3) // v-if, v-component, v-text
         expect(el.textContent).toBe('hello world')
         done()
@@ -274,7 +274,7 @@ if (_.inBrowser) {
         }
       })
       expect(el.textContent).toBe('')
-      vm._children[0].$emit('ok')
+      vm.$children[0].$emit('ok')
       expect(el.textContent).toBe('AAA')
     })
 
@@ -294,12 +294,12 @@ if (_.inBrowser) {
           }
         }
       })
-      vm._children[0].$emit('ok')
+      vm.$children[0].$emit('ok')
       vm.view = 'view-b'
       _.nextTick(function () {
         expect(el.textContent).toBe('AAA')
         // old vm is already removed, this is the new vm
-        vm._children[0].$emit('ok')
+        vm.$children[0].$emit('ok')
         expect(el.textContent).toBe('BBB')
         done()
       })
@@ -403,12 +403,12 @@ if (_.inBrowser) {
       })
       vm.view = 'test2'
       _.nextTick(function () {
-        expect(vm._children.length).toBe(2)
-        var child = vm._children[0]
-        var child2 = vm._children[1]
+        expect(vm.$children.length).toBe(2)
+        var child = vm.$children[0]
+        var child2 = vm.$children[1]
         vm._directives[0].unbind()
         expect(vm._directives[0].cache).toBeNull()
-        expect(vm._children.length).toBe(0)
+        expect(vm.$children.length).toBe(0)
         expect(child._isDestroyed).toBe(true)
         expect(child2._isDestroyed).toBe(true)
         done()

+ 13 - 13
test/unit/specs/directives/if_spec.js

@@ -24,20 +24,20 @@ if (_.inBrowser) {
       })
       // lazy instantitation
       expect(el.innerHTML).toBe('')
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
       vm.test = true
       _.nextTick(function () {
         expect(el.innerHTML).toBe('<div><test>A</test></div>')
-        expect(vm._children.length).toBe(1)
+        expect(vm.$children.length).toBe(1)
         vm.test = false
         _.nextTick(function () {
           expect(el.innerHTML).toBe('')
-          expect(vm._children.length).toBe(0)
+          expect(vm.$children.length).toBe(0)
           vm.test = true
           _.nextTick(function () {
             expect(el.innerHTML).toBe('<div><test>A</test></div>')
-            expect(vm._children.length).toBe(1)
-            var child = vm._children[0]
+            expect(vm.$children.length).toBe(1)
+            var child = vm.$children[0]
             vm.$destroy()
             expect(child._isDestroyed).toBe(true)
             done()
@@ -87,18 +87,18 @@ if (_.inBrowser) {
       })
       vm.$appendTo(document.body)
       expect(el.innerHTML).toBe('')
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
       vm.ok = true
       _.nextTick(function () {
         expect(el.innerHTML).toBe('<test>123</test>')
-        expect(vm._children.length).toBe(1)
+        expect(vm.$children.length).toBe(1)
         expect(attachSpy).toHaveBeenCalled()
         expect(readySpy).toHaveBeenCalled()
         vm.ok = false
         _.nextTick(function () {
           expect(detachSpy).toHaveBeenCalled()
           expect(el.innerHTML).toBe('')
-          expect(vm._children.length).toBe(0)
+          expect(vm.$children.length).toBe(0)
           vm.$remove()
           done()
         })
@@ -123,28 +123,28 @@ if (_.inBrowser) {
         }
       })
       expect(el.innerHTML).toBe('')
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
       // toggle if with lazy instantiation
       vm.ok = true
       _.nextTick(function () {
         expect(el.innerHTML).toBe('<component>AAA</component>')
-        expect(vm._children.length).toBe(1)
+        expect(vm.$children.length).toBe(1)
         // switch view when if=true
         vm.view = 'view-b'
         _.nextTick(function () {
           expect(el.innerHTML).toBe('<component>BBB</component>')
-          expect(vm._children.length).toBe(1)
+          expect(vm.$children.length).toBe(1)
           // toggle if when already instantiated
           vm.ok = false
           _.nextTick(function () {
             expect(el.innerHTML).toBe('')
-            expect(vm._children.length).toBe(0)
+            expect(vm.$children.length).toBe(0)
             // toggle if and switch view at the same time
             vm.view = 'view-a'
             vm.ok = true
             _.nextTick(function () {
               expect(el.innerHTML).toBe('<component>AAA</component>')
-              expect(vm._children.length).toBe(1)
+              expect(vm.$children.length).toBe(1)
               done()
             })
           })

+ 1 - 1
test/unit/specs/directives/prop_spec.js

@@ -199,7 +199,7 @@ if (_.inBrowser) {
           }
         }
       })
-      var child = vm._children[0]
+      var child = vm.$children[0]
       expect(el.firstChild.textContent).toBe('A B')
       child.aa = 'AA'
       vm.b = 'BB'

+ 11 - 11
test/unit/specs/directives/repeat_spec.js

@@ -489,7 +489,7 @@ if (_.inBrowser) {
           }
         })
         assertMarkup()
-        var oldVms = vm._children.slice()
+        var oldVms = vm.$children.slice()
         // swap the data with different objects, but with
         // the same ID!
         vm.list = [
@@ -501,7 +501,7 @@ if (_.inBrowser) {
           // should reuse old vms!
           var i = 2
           while (i--) {
-            expect(vm._children[i]).toBe(oldVms[i])
+            expect(vm.$children[i]).toBe(oldVms[i])
           }
           next()
         })
@@ -611,7 +611,7 @@ if (_.inBrowser) {
         }
       })
       vm._directives[0].unbind()
-      expect(vm._children.length).toBe(0)
+      expect(vm.$children.length).toBe(0)
     })
 
     it('with transition', function (done) {
@@ -655,10 +655,10 @@ if (_.inBrowser) {
           vals: [1, 2]
         }
       })
-      vm._children[0].$value = 'c'
-      var key = vm._children[2].$key
-      vm._children[2].$value = 'd'
-      vm._children[4].val = 3
+      vm.$children[0].$value = 'c'
+      var key = vm.$children[2].$key
+      vm.$children[2].$value = 'd'
+      vm.$children[4].val = 3
       _.nextTick(function () {
         expect(vm.items[0]).toBe('c')
         expect(vm.obj[key]).toBe('d')
@@ -675,7 +675,7 @@ if (_.inBrowser) {
           items: ['a', 'b']
         }
       })
-      vm._children[0].$value = 'c'
+      vm.$children[0].$value = 'c'
       _.nextTick(function () {
         expect(hasWarned(_, 'use an Array of Objects instead')).toBe(true)
         done()
@@ -703,7 +703,7 @@ if (_.inBrowser) {
         })
         assertMarkup()
 
-        var oldVms = vm._children.slice()
+        var oldVms = vm.$children.slice()
 
         vm.list = [
           { id: 1, msg: 'wa', list: [
@@ -718,9 +718,9 @@ if (_.inBrowser) {
           // should reuse old vms!
           var i = 2
           while (i--) {
-            expect(vm._children[i]).toBe(oldVms[i])
+            expect(vm.$children[i]).toBe(oldVms[i])
           }
-          expect(vm._children[0]._children[0]).toBe(oldVms[0]._children[0])
+          expect(vm.$children[0].$children[0]).toBe(oldVms[0].$children[0])
           next()
         })
 

+ 1 - 1
test/unit/specs/instance/scope_spec.js

@@ -122,7 +122,7 @@ describe('Instance Scope', function () {
           }
         }
       })
-      var child = vm._children[0]
+      var child = vm.$children[0]
       expect(child.a).toBe(1)
       expect(child.b).toBe(2)
       expect(child.c).toBe(3)