From c2ecb7ed78a426152cf9a829726747908126f2cc Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Fri, 17 Jun 2022 09:36:43 +0200 Subject: [PATCH] support multiple community description callbacks (#280) --- packages/status-js/src/client/community/community.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/status-js/src/client/community/community.ts b/packages/status-js/src/client/community/community.ts index 6c197621..cadd3aeb 100644 --- a/packages/status-js/src/client/community/community.ts +++ b/packages/status-js/src/client/community/community.ts @@ -27,7 +27,7 @@ export class Community { public description!: CommunityDescription public chats: Map #members: Map - public callback: ((description: CommunityDescription) => void) | undefined + #descriptionCallbacks: Set<(description: CommunityDescription) => void> constructor(client: Client, publicKey: string) { this.client = client @@ -37,6 +37,7 @@ export class Community { this.chats = new Map() this.#members = new Map() + this.#descriptionCallbacks = new Set() } public async start() { @@ -220,7 +221,9 @@ export class Community { this.description = description // callback - this.callback?.(this.description) + this.#descriptionCallbacks.forEach(callback => + callback({ ...this.description }) + ) // Chats // handle @@ -231,10 +234,10 @@ export class Community { } public onChange = (callback: (description: CommunityDescription) => void) => { - this.callback = callback + this.#descriptionCallbacks.add(callback) return () => { - this.callback = undefined + this.#descriptionCallbacks.delete(callback) } }