From f72e804d08ece7bdf61a653447d1be5777013d8a Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 9 Sep 2022 11:48:24 +0200 Subject: [PATCH] Removed event bus --- apps/comments-ui/src/utils/event-bus.js | 56 ------------------------- 1 file changed, 56 deletions(-) delete mode 100644 apps/comments-ui/src/utils/event-bus.js diff --git a/apps/comments-ui/src/utils/event-bus.js b/apps/comments-ui/src/utils/event-bus.js deleted file mode 100644 index 6d68f1a24a..0000000000 --- a/apps/comments-ui/src/utils/event-bus.js +++ /dev/null @@ -1,56 +0,0 @@ -class EventBus { - listeners = new Map() - - addListener(owner, type, listener) { - const existing = this.listeners.get(owner); - if (existing) { - existing.push({type, listener}); - } else { - this.listeners.set(owner, [{type, listener}]); - } - } - - /** - * - * @param {*} owner - * @param {*} [type] Leave out if you want to remove all types - */ - removeListener(owner, type) { - if (type) { - const existing = this.listeners.get(owner); - if (existing) { - this.listeners.set( - owner, - existing.filter(t => t.type !== type) - ); - } - } else { - this.listeners.delete(owner); - } - } - - /** - * - * @param {*} type - * @param {*} value - * @param {*} [excludeOwner] Don't send the event to this owner (e.g. the sender of the message doesn't want to receive it when it is also listening for it) - * @returns - */ - sendEvent(type, value, excludeOwner) { - const values = []; - for (const owner of this.listeners.values()) { - if (excludeOwner !== undefined && owner === excludeOwner) { - return; - } - - for (const listener of owner) { - if (listener.type === type) { - values.push(listener.listener(value, type)); - } - } - } - return values; - } -} - -export const GlobalEventBus = new EventBus();