pulsar/src/item-registry.js
2018-01-22 16:14:25 -08:00

22 lines
389 B
JavaScript

module.exports =
class ItemRegistry {
constructor () {
this.items = new WeakSet()
}
addItem (item) {
if (this.hasItem(item)) {
throw new Error(`The workspace can only contain one instance of item ${item}`)
}
return this.items.add(item)
}
removeItem (item) {
return this.items.delete(item)
}
hasItem (item) {
return this.items.has(item)
}
}