12345678910111213141516171819202122 |
- const EventBus = {
- events: {} as any,
-
- on: function (eventName: string, callback: Function) {
- this.events[eventName] = callback;
- },
-
- emit: function (eventName: string, data: any) {
- if (this.events[eventName]) {
- this.events[eventName](data);
- }
- },
-
- off: function (eventName: string) {
- if (this.events[eventName]) {
- delete this.events[eventName];
- }
- }
- };
- export default EventBus;
|