mirror of https://github.com/waku-org/js-waku.git
Use Set to facilitate removal of observers
This commit is contained in:
parent
9244674cf5
commit
af1e97fafe
|
@ -65,7 +65,7 @@ export class WakuRelay extends Gossipsub implements Pubsub {
|
|||
* Observers under key "" are always called.
|
||||
*/
|
||||
public observers: {
|
||||
[contentTopic: string]: Array<(message: WakuMessage) => void>;
|
||||
[contentTopic: string]: Set<(message: WakuMessage) => void>;
|
||||
};
|
||||
|
||||
constructor(
|
||||
|
@ -131,15 +131,15 @@ export class WakuRelay extends Gossipsub implements Pubsub {
|
|||
): void {
|
||||
if (contentTopics.length === 0) {
|
||||
if (!this.observers['']) {
|
||||
this.observers[''] = [];
|
||||
this.observers[''] = new Set();
|
||||
}
|
||||
this.observers[''].push(callback);
|
||||
this.observers[''].add(callback);
|
||||
} else {
|
||||
contentTopics.forEach((contentTopic) => {
|
||||
if (!this.observers[contentTopic]) {
|
||||
this.observers[contentTopic] = [];
|
||||
this.observers[contentTopic] = new Set();
|
||||
}
|
||||
this.observers[contentTopic].push(callback);
|
||||
this.observers[contentTopic].add(callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue