2020-10-20 10:25:04 +00:00
|
|
|
import {Subscribable} from $to_relative "/js/store/Subscribable.js"
|
2020-10-15 09:06:41 +00:00
|
|
|
|
|
|
|
class SubscribeSet extends Subscribable {
|
2020-10-19 11:43:33 +00:00
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
Object.assign(this.events, {
|
|
|
|
addItem: [],
|
|
|
|
deleteItem: [],
|
|
|
|
changeItem: [],
|
|
|
|
askAdd: []
|
|
|
|
})
|
|
|
|
Object.assign(this.eventDeps, {
|
|
|
|
addItem: ["changeItem"],
|
|
|
|
deleteItem: ["changeItem"],
|
|
|
|
changeItem: [],
|
|
|
|
askAdd: []
|
|
|
|
})
|
|
|
|
this.set = new Set()
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
has(key) {
|
|
|
|
return this.set.has(key)
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
forEach(f) {
|
|
|
|
for (const key of this.set.keys()) {
|
|
|
|
f(key)
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
askAdd(key) {
|
|
|
|
this.broadcast("askAdd", key)
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
add(key) {
|
|
|
|
if (!this.set.has(key)) {
|
|
|
|
this.set.add(key)
|
|
|
|
this.broadcast("addItem", key)
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
delete(key) {
|
|
|
|
if (this.set.has(key)) {
|
|
|
|
this.set.delete(key)
|
|
|
|
this.broadcast("deleteItem", key)
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 09:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 11:43:33 +00:00
|
|
|
export {SubscribeSet}
|