Preferred to object when possible.
This commit is contained in:
Franck Royer 2022-05-26 16:05:36 +10:00
parent 5687908ca0
commit 2e09b6dec3
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 5 additions and 7 deletions

View File

@ -37,16 +37,14 @@ type UnsubscribeFunction = () => Promise<void>;
* WakuFilter can be used as a light filter node, but cannot currently be used as a full node that pushes messages to clients. * 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 { export class WakuFilter {
private subscriptions: { private subscriptions: Map<string, FilterCallback>;
[requestId: string]: FilterCallback;
};
public decryptionKeys: Map< public decryptionKeys: Map<
Uint8Array, Uint8Array,
{ method?: DecryptionMethod; contentTopics?: string[] } { method?: DecryptionMethod; contentTopics?: string[] }
>; >;
constructor(public libp2p: Libp2p) { constructor(public libp2p: Libp2p) {
this.subscriptions = {}; this.subscriptions = new Map();
this.decryptionKeys = new Map(); this.decryptionKeys = new Map();
this.libp2p.handle(FilterCodec, this.onRequest.bind(this)); this.libp2p.handle(FilterCodec, this.onRequest.bind(this));
} }
@ -122,7 +120,7 @@ export class WakuFilter {
requestId: string, requestId: string,
messages: WakuMessageProto[] messages: WakuMessageProto[]
): Promise<void> { ): Promise<void> {
const callback = this.subscriptions[requestId]; const callback = this.subscriptions.get(requestId);
if (!callback) { if (!callback) {
log(`No callback registered for request ID ${requestId}`); log(`No callback registered for request ID ${requestId}`);
return; return;
@ -149,11 +147,11 @@ export class WakuFilter {
} }
private addCallback(requestId: string, callback: FilterCallback): void { private addCallback(requestId: string, callback: FilterCallback): void {
this.subscriptions[requestId] = callback; this.subscriptions.set(requestId, callback);
} }
private removeCallback(requestId: string): void { private removeCallback(requestId: string): void {
delete this.subscriptions[requestId]; this.subscriptions.delete(requestId);
} }
private async unsubscribe( private async unsubscribe(