mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 12:45:21 +00:00
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.
|
* Observers under key "" are always called.
|
||||||
*/
|
*/
|
||||||
public observers: {
|
public observers: {
|
||||||
[contentTopic: string]: Array<(message: WakuMessage) => void>;
|
[contentTopic: string]: Set<(message: WakuMessage) => void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -131,15 +131,15 @@ export class WakuRelay extends Gossipsub implements Pubsub {
|
|||||||
): void {
|
): void {
|
||||||
if (contentTopics.length === 0) {
|
if (contentTopics.length === 0) {
|
||||||
if (!this.observers['']) {
|
if (!this.observers['']) {
|
||||||
this.observers[''] = [];
|
this.observers[''] = new Set();
|
||||||
}
|
}
|
||||||
this.observers[''].push(callback);
|
this.observers[''].add(callback);
|
||||||
} else {
|
} else {
|
||||||
contentTopics.forEach((contentTopic) => {
|
contentTopics.forEach((contentTopic) => {
|
||||||
if (!this.observers[contentTopic]) {
|
if (!this.observers[contentTopic]) {
|
||||||
this.observers[contentTopic] = [];
|
this.observers[contentTopic] = new Set();
|
||||||
}
|
}
|
||||||
this.observers[contentTopic].push(callback);
|
this.observers[contentTopic].add(callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user