Skip to content

Commit 3d5b934

Browse files
committed
use $remove everywhere
1 parent 635fada commit 3d5b934

File tree

6 files changed

+10
-25
lines changed

6 files changed

+10
-25
lines changed

src/compiler/compile.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ function teardownDirs (vm, dirs) {
9898
var i = dirs.length
9999
while (i--) {
100100
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])
105102
}
106103
}
107104

src/instance/compile.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ exports._destroy = function (remove, deferCleanup) {
9595
// if parent is not being destroyed as well.
9696
var parent = this.$parent
9797
if (parent && !parent._isBeingDestroyed) {
98-
i = parent._children.indexOf(this)
99-
parent._children.splice(i, 1)
98+
parent._children.$remove(this)
10099
}
101100
// same for transclusion host.
102101
var host = this._host
103102
if (host && !host._isBeingDestroyed) {
104-
i = host._transCpnts.indexOf(this)
105-
host._transCpnts.splice(i, 1)
103+
host._transCpnts.$remove(this)
106104
}
107105
// destroy all children.
108106
i = this._children.length

src/observer/array.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ _.define(
7878
arrayProto,
7979
'$remove',
8080
function $remove (index) {
81+
if (!this.length) return
8182
if (typeof index !== 'number') {
8283
index = this.indexOf(index)
8384
}
8485
if (index > -1) {
85-
return this.splice(index, 1)[0]
86+
this.splice(index, 1)
8687
}
8788
}
8889
)

src/observer/dep.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ p.addSub = function (sub) {
3232
*/
3333

3434
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)
3936
}
4037

4138
/**

src/observer/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ p.convert = function (key, val) {
180180
// remove dep from old value
181181
var oldChildOb = val && val.__ob__
182182
if (oldChildOb) {
183-
var oldDeps = oldChildOb.deps
184-
oldDeps.splice(oldDeps.indexOf(dep), 1)
183+
oldChildOb.deps.$remove(dep)
185184
}
186185
val = newVal
187186
// add dep to new value
@@ -229,7 +228,7 @@ p.addVm = function (vm) {
229228
*/
230229

231230
p.removeVm = function (vm) {
232-
this.vms.splice(this.vms.indexOf(vm), 1)
231+
this.vms.$remove(vm)
233232
}
234233

235234
module.exports = Observer

src/watcher.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ p.addCb = function (cb) {
202202
p.removeCb = function (cb) {
203203
var cbs = this.cbs
204204
if (cbs.length > 1) {
205-
var i = cbs.indexOf(cb)
206-
if (i > -1) {
207-
cbs.splice(i, 1)
208-
}
205+
cbs.$remove(cb)
209206
} else if (cb === cbs[0]) {
210207
this.teardown()
211208
}
@@ -221,11 +218,7 @@ p.teardown = function () {
221218
// we can skip this if the vm if being destroyed
222219
// which can improve teardown performance.
223220
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)
229222
}
230223
for (var id in this.deps) {
231224
this.deps[id].removeSub(this)

0 commit comments

Comments
 (0)