Minor code dedup.
This commit is contained in:
parent
ce7bc9f438
commit
61c61adea1
@ -113,20 +113,14 @@ export default class Collection extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear () {
|
clear () {
|
||||||
forEach(this._items, (_, key) => {
|
forEach(this._items, (_, key) => this._remove(key))
|
||||||
delete this._items[key]
|
|
||||||
this._size--
|
|
||||||
this._touch(ACTION_REMOVE, key)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remove (keyOrObjectWithId) {
|
remove (keyOrObjectWithId) {
|
||||||
const [key] = this._resolveItem(keyOrObjectWithId)
|
const [key] = this._resolveItem(keyOrObjectWithId)
|
||||||
this._assertHas(key)
|
this._assertHas(key)
|
||||||
|
|
||||||
delete this._items[key]
|
this._remove(key)
|
||||||
this._size--
|
|
||||||
this._touch(ACTION_REMOVE, key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set (keyOrObjectWithId, valueIfKey = undefined) {
|
set (keyOrObjectWithId, valueIfKey = undefined) {
|
||||||
@ -157,9 +151,7 @@ export default class Collection extends EventEmitter {
|
|||||||
const [key] = this._resolveItem(keyOrObjectWithId)
|
const [key] = this._resolveItem(keyOrObjectWithId)
|
||||||
|
|
||||||
if (this.has(key)) {
|
if (this.has(key)) {
|
||||||
delete this._items[key]
|
this._remove(key)
|
||||||
this._size--
|
|
||||||
this._touch(ACTION_REMOVE, key)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,6 +316,12 @@ export default class Collection extends EventEmitter {
|
|||||||
return typeof key === 'number' || typeof key === 'string'
|
return typeof key === 'number' || typeof key === 'string'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_remove (key) {
|
||||||
|
delete this._items[key]
|
||||||
|
this._size--
|
||||||
|
this._touch(ACTION_REMOVE)
|
||||||
|
}
|
||||||
|
|
||||||
_resolveItem (keyOrObjectWithId, valueIfKey = undefined) {
|
_resolveItem (keyOrObjectWithId, valueIfKey = undefined) {
|
||||||
if (valueIfKey !== undefined) {
|
if (valueIfKey !== undefined) {
|
||||||
this._assertValidKey(keyOrObjectWithId)
|
this._assertValidKey(keyOrObjectWithId)
|
||||||
|
Loading…
Reference in New Issue
Block a user