From 2e09b6dec36e0698ab7614cc37b6dc9a96518e5d Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 26 May 2022 16:05:36 +1000 Subject: [PATCH] Use Map Preferred to object when possible. --- src/lib/waku_filter/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib/waku_filter/index.ts b/src/lib/waku_filter/index.ts index 883e5307cb..16785b339f 100644 --- a/src/lib/waku_filter/index.ts +++ b/src/lib/waku_filter/index.ts @@ -37,16 +37,14 @@ type UnsubscribeFunction = () => Promise; * WakuFilter can be used as a light filter node, but cannot currently be used as a full node that pushes messages to clients. */ export class WakuFilter { - private subscriptions: { - [requestId: string]: FilterCallback; - }; + private subscriptions: Map; public decryptionKeys: Map< Uint8Array, { method?: DecryptionMethod; contentTopics?: string[] } >; constructor(public libp2p: Libp2p) { - this.subscriptions = {}; + this.subscriptions = new Map(); this.decryptionKeys = new Map(); this.libp2p.handle(FilterCodec, this.onRequest.bind(this)); } @@ -122,7 +120,7 @@ export class WakuFilter { requestId: string, messages: WakuMessageProto[] ): Promise { - const callback = this.subscriptions[requestId]; + const callback = this.subscriptions.get(requestId); if (!callback) { log(`No callback registered for request ID ${requestId}`); return; @@ -149,11 +147,11 @@ export class WakuFilter { } private addCallback(requestId: string, callback: FilterCallback): void { - this.subscriptions[requestId] = callback; + this.subscriptions.set(requestId, callback); } private removeCallback(requestId: string): void { - delete this.subscriptions[requestId]; + this.subscriptions.delete(requestId); } private async unsubscribe(