too
This commit is contained in:
parent
4fdc567e08
commit
e00bfd8879
51 changed files with 1203 additions and 833 deletions
|
|
@ -6,21 +6,13 @@ class TarinaiEventBus {
|
|||
}
|
||||
|
||||
on(type, handler) {
|
||||
if (!type || typeof handler !== "function") return () => {};
|
||||
if (!type || typeof handler !== "function") return;
|
||||
let list = this.handlers.get(type);
|
||||
if (!list) {
|
||||
list = new Set();
|
||||
this.handlers.set(type, list);
|
||||
}
|
||||
list.add(handler);
|
||||
return () => this.off(type, handler);
|
||||
}
|
||||
|
||||
off(type, handler) {
|
||||
const list = this.handlers.get(type);
|
||||
if (!list) return;
|
||||
list.delete(handler);
|
||||
if (!list.size) this.handlers.delete(type);
|
||||
}
|
||||
|
||||
emit(type, detail = {}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue