Skip to content

Commit 697c431

Browse files
committed
feat(eventemitter): add unsubscribe function
1 parent 9f527f5 commit 697c431

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/common/event/eventEmitter.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ export class EventEmitter {
2121
}
2222
}
2323

24-
// TODO
25-
public unsubscribe() {}
24+
public unsubscribe(name: string | string[]) {
25+
if (Array.isArray(name)) {
26+
name.forEach((key: string) => {
27+
this._events.delete(key);
28+
});
29+
} else {
30+
this._events.delete(name);
31+
}
32+
}
2633

2734
public assignEvent<T>(name: string, callback: Function) {
2835
const event = this._events.get(name);

0 commit comments

Comments
 (0)