File tree 9 files changed +22
-42
lines changed
test/unit/specs/directives
9 files changed +22
-42
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,6 @@ exports.$addChild = function (opts, BaseCtor) {
21
21
: BaseCtor . options . inherit
22
22
if ( inherit ) {
23
23
var ctors = parent . _childCtors
24
- if ( ! ctors ) {
25
- ctors = parent . _childCtors = { }
26
- }
27
24
ChildVue = ctors [ BaseCtor . cid ]
28
25
if ( ! ChildVue ) {
29
26
var optionName = BaseCtor . options . name
@@ -45,9 +42,6 @@ exports.$addChild = function (opts, BaseCtor) {
45
42
opts . _parent = parent
46
43
opts . _root = parent . $root
47
44
var child = new ChildVue ( opts )
48
- if ( ! this . _children ) {
49
- this . _children = [ ]
50
- }
51
45
this . _children . push ( child )
52
46
return child
53
47
}
Original file line number Diff line number Diff line change @@ -122,13 +122,11 @@ exports.$broadcast = function (event) {
122
122
// then there's no need to broadcast.
123
123
if ( ! this . _eventsCount [ event ] ) return
124
124
var children = this . _children
125
- if ( children ) {
126
- for ( var i = 0 , l = children . length ; i < l ; i ++ ) {
127
- var child = children [ i ]
128
- child . $emit . apply ( child , arguments )
129
- if ( ! child . _eventCancelled ) {
130
- child . $broadcast . apply ( child , arguments )
131
- }
125
+ for ( var i = 0 , l = children . length ; i < l ; i ++ ) {
126
+ var child = children [ i ]
127
+ child . $emit . apply ( child , arguments )
128
+ if ( ! child . _eventCancelled ) {
129
+ child . $broadcast . apply ( child , arguments )
132
130
}
133
131
}
134
132
return this
Original file line number Diff line number Diff line change @@ -53,17 +53,13 @@ module.exports = {
53
53
compile : function ( template ) {
54
54
var vm = this . vm
55
55
var frag = templateParser . clone ( template )
56
- var originalChildLength = vm . _children
57
- ? vm . _children . length
58
- : 0
56
+ var originalChildLength = vm . _children . length
59
57
this . unlink = this . linker
60
58
? this . linker ( vm , frag )
61
59
: vm . $compile ( frag )
62
60
transition . blockAppend ( frag , this . end , vm )
63
- this . children = vm . _children
64
- ? vm . _children . slice ( originalChildLength )
65
- : null
66
- if ( this . children && _ . inDoc ( vm . $el ) ) {
61
+ this . children = vm . _children . slice ( originalChildLength )
62
+ if ( this . children . length && _ . inDoc ( vm . $el ) ) {
67
63
this . children . forEach ( function ( child ) {
68
64
child . _callHook ( 'attached' )
69
65
} )
Original file line number Diff line number Diff line change @@ -122,11 +122,9 @@ exports._destroy = function (remove, deferCleanup) {
122
122
parent . _children . splice ( i , 1 )
123
123
}
124
124
// destroy all children.
125
- if ( this . _children ) {
126
- i = this . _children . length
127
- while ( i -- ) {
128
- this . _children [ i ] . $destroy ( )
129
- }
125
+ i = this . _children . length
126
+ while ( i -- ) {
127
+ this . _children [ i ] . $destroy ( )
130
128
}
131
129
// teardown parent linkers
132
130
if ( this . _containerUnlinkFn ) {
Original file line number Diff line number Diff line change @@ -80,7 +80,6 @@ exports._initDOMHooks = function () {
80
80
function onAttached ( ) {
81
81
this . _isAttached = true
82
82
var children = this . _children
83
- if ( ! children ) return
84
83
for ( var i = 0 , l = children . length ; i < l ; i ++ ) {
85
84
var child = children [ i ]
86
85
if ( ! child . _isAttached && inDoc ( child . $el ) ) {
@@ -96,7 +95,6 @@ function onAttached () {
96
95
function onDetached ( ) {
97
96
this . _isAttached = false
98
97
var children = this . _children
99
- if ( ! children ) return
100
98
for ( var i = 0 , l = children . length ; i < l ; i ++ ) {
101
99
var child = children [ i ]
102
100
if ( child . _isAttached && ! inDoc ( child . $el ) ) {
Original file line number Diff line number Diff line change @@ -46,9 +46,8 @@ exports._init = function (options) {
46
46
this . _isBeingDestroyed = false
47
47
48
48
// children
49
- this . _children = // @type {Array }
50
- this . _childCtors = null // @type {Object } - hash to cache
51
- // child constructors
49
+ this . _children = [ ]
50
+ this . _childCtors = { }
52
51
53
52
// merge options.
54
53
options = this . $options = mergeOptions (
Original file line number Diff line number Diff line change @@ -117,14 +117,11 @@ exports._digest = function () {
117
117
this . _watcherList [ i ] . update ( )
118
118
}
119
119
var children = this . _children
120
- var child
121
- if ( children ) {
122
- i = children . length
123
- while ( i -- ) {
124
- child = children [ i ]
125
- if ( child . $options . inherit ) {
126
- child . _digest ( )
127
- }
120
+ i = children . length
121
+ while ( i -- ) {
122
+ var child = children [ i ]
123
+ if ( child . $options . inherit ) {
124
+ child . _digest ( )
128
125
}
129
126
}
130
127
}
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ if (_.inBrowser) {
189
189
}
190
190
} )
191
191
expect ( el . textContent ) . toBe ( '' )
192
- expect ( vm . _children ) . toBeNull ( )
192
+ expect ( vm . _children . length ) . toBe ( 0 )
193
193
expect ( vm . _directives . length ) . toBe ( 1 ) // v-if
194
194
vm . ok = true
195
195
_ . nextTick ( function ( ) {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ if (_.inBrowser) {
28
28
} )
29
29
// lazy instantitation
30
30
expect ( el . innerHTML ) . toBe ( wrap ( '' ) )
31
- expect ( vm . _children ) . toBeNull ( )
31
+ expect ( vm . _children . length ) . toBe ( 0 )
32
32
vm . test = true
33
33
_ . nextTick ( function ( ) {
34
34
expect ( el . innerHTML ) . toBe ( wrap ( '<div><div>A</div><!--v-component--></div>' ) )
@@ -91,7 +91,7 @@ if (_.inBrowser) {
91
91
} )
92
92
vm . $appendTo ( document . body )
93
93
expect ( el . innerHTML ) . toBe ( wrap ( '' ) )
94
- expect ( vm . _children ) . toBeNull ( )
94
+ expect ( vm . _children . length ) . toBe ( 0 )
95
95
vm . ok = true
96
96
_ . nextTick ( function ( ) {
97
97
expect ( el . innerHTML ) . toBe ( wrap ( '<div>123</div><!--v-component-->' ) )
@@ -127,7 +127,7 @@ if (_.inBrowser) {
127
127
}
128
128
} )
129
129
expect ( el . innerHTML ) . toBe ( wrap ( '' ) )
130
- expect ( vm . _children ) . toBeNull ( )
130
+ expect ( vm . _children . length ) . toBe ( 0 )
131
131
// toggle if with lazy instantiation
132
132
vm . ok = true
133
133
_ . nextTick ( function ( ) {
You can’t perform that action at this time.
0 commit comments