Minor code dedup.

This commit is contained in:
Julien Fontanet 2016-01-21 15:42:34 +01:00
parent ce7bc9f438
commit 61c61adea1

View File

@ -113,20 +113,14 @@ export default class Collection extends EventEmitter {
}
clear () {
forEach(this._items, (_, key) => {
delete this._items[key]
this._size--
this._touch(ACTION_REMOVE, key)
})
forEach(this._items, (_, key) => this._remove(key))
}
remove (keyOrObjectWithId) {
const [key] = this._resolveItem(keyOrObjectWithId)
this._assertHas(key)
delete this._items[key]
this._size--
this._touch(ACTION_REMOVE, key)
this._remove(key)
}
set (keyOrObjectWithId, valueIfKey = undefined) {
@ -157,9 +151,7 @@ export default class Collection extends EventEmitter {
const [key] = this._resolveItem(keyOrObjectWithId)
if (this.has(key)) {
delete this._items[key]
this._size--
this._touch(ACTION_REMOVE, key)
this._remove(key)
}
}
@ -324,6 +316,12 @@ export default class Collection extends EventEmitter {
return typeof key === 'number' || typeof key === 'string'
}
_remove (key) {
delete this._items[key]
this._size--
this._touch(ACTION_REMOVE)
}
_resolveItem (keyOrObjectWithId, valueIfKey = undefined) {
if (valueIfKey !== undefined) {
this._assertValidKey(keyOrObjectWithId)