File tree 6 files changed +10
-25
lines changed
6 files changed +10
-25
lines changed Original file line number Diff line number Diff line change @@ -98,10 +98,7 @@ function teardownDirs (vm, dirs) {
98
98
var i = dirs . length
99
99
while ( i -- ) {
100
100
dirs [ i ] . _teardown ( )
101
- }
102
- i = vm . _directives . indexOf ( dirs [ 0 ] )
103
- if ( i > - 1 ) {
104
- vm . _directives . splice ( i , dirs . length )
101
+ vm . _directives . $remove ( dirs [ i ] )
105
102
}
106
103
}
107
104
Original file line number Diff line number Diff line change @@ -95,14 +95,12 @@ exports._destroy = function (remove, deferCleanup) {
95
95
// if parent is not being destroyed as well.
96
96
var parent = this . $parent
97
97
if ( parent && ! parent . _isBeingDestroyed ) {
98
- i = parent . _children . indexOf ( this )
99
- parent . _children . splice ( i , 1 )
98
+ parent . _children . $remove ( this )
100
99
}
101
100
// same for transclusion host.
102
101
var host = this . _host
103
102
if ( host && ! host . _isBeingDestroyed ) {
104
- i = host . _transCpnts . indexOf ( this )
105
- host . _transCpnts . splice ( i , 1 )
103
+ host . _transCpnts . $remove ( this )
106
104
}
107
105
// destroy all children.
108
106
i = this . _children . length
Original file line number Diff line number Diff line change @@ -78,11 +78,12 @@ _.define(
78
78
arrayProto ,
79
79
'$remove' ,
80
80
function $remove ( index ) {
81
+ if ( ! this . length ) return
81
82
if ( typeof index !== 'number' ) {
82
83
index = this . indexOf ( index )
83
84
}
84
85
if ( index > - 1 ) {
85
- return this . splice ( index , 1 ) [ 0 ]
86
+ this . splice ( index , 1 )
86
87
}
87
88
}
88
89
)
Original file line number Diff line number Diff line change @@ -32,10 +32,7 @@ p.addSub = function (sub) {
32
32
*/
33
33
34
34
p . removeSub = function ( sub ) {
35
- if ( this . subs . length ) {
36
- var i = this . subs . indexOf ( sub )
37
- if ( i > - 1 ) this . subs . splice ( i , 1 )
38
- }
35
+ this . subs . $remove ( sub )
39
36
}
40
37
41
38
/**
Original file line number Diff line number Diff line change @@ -180,8 +180,7 @@ p.convert = function (key, val) {
180
180
// remove dep from old value
181
181
var oldChildOb = val && val . __ob__
182
182
if ( oldChildOb ) {
183
- var oldDeps = oldChildOb . deps
184
- oldDeps . splice ( oldDeps . indexOf ( dep ) , 1 )
183
+ oldChildOb . deps . $remove ( dep )
185
184
}
186
185
val = newVal
187
186
// add dep to new value
@@ -229,7 +228,7 @@ p.addVm = function (vm) {
229
228
*/
230
229
231
230
p . removeVm = function ( vm ) {
232
- this . vms . splice ( this . vms . indexOf ( vm ) , 1 )
231
+ this . vms . $remove ( vm )
233
232
}
234
233
235
234
module . exports = Observer
Original file line number Diff line number Diff line change @@ -202,10 +202,7 @@ p.addCb = function (cb) {
202
202
p . removeCb = function ( cb ) {
203
203
var cbs = this . cbs
204
204
if ( cbs . length > 1 ) {
205
- var i = cbs . indexOf ( cb )
206
- if ( i > - 1 ) {
207
- cbs . splice ( i , 1 )
208
- }
205
+ cbs . $remove ( cb )
209
206
} else if ( cb === cbs [ 0 ] ) {
210
207
this . teardown ( )
211
208
}
@@ -221,11 +218,7 @@ p.teardown = function () {
221
218
// we can skip this if the vm if being destroyed
222
219
// which can improve teardown performance.
223
220
if ( ! this . vm . _isBeingDestroyed ) {
224
- var list = this . vm . _watcherList
225
- var i = list . indexOf ( this )
226
- if ( i > - 1 ) {
227
- list . splice ( i , 1 )
228
- }
221
+ this . vm . _watcherList . $remove ( this )
229
222
}
230
223
for ( var id in this . deps ) {
231
224
this . deps [ id ] . removeSub ( this )
You can’t perform that action at this time.
0 commit comments