From c3608006314eba7defd1c27b0a550c2eb15ad3f6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 9 Jun 2020 15:26:13 -0600 Subject: [PATCH] Add token.remove() handling to room list temp proxy Fixes https://github.com/vector-im/riot-web/issues/13930 --- .../room-list/RoomListStoreTempProxy.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/stores/room-list/RoomListStoreTempProxy.ts b/src/stores/room-list/RoomListStoreTempProxy.ts index 0268cf0a46..13129f4bdb 100644 --- a/src/stores/room-list/RoomListStoreTempProxy.ts +++ b/src/stores/room-list/RoomListStoreTempProxy.ts @@ -31,11 +31,14 @@ export class RoomListStoreTempProxy { return SettingsStore.isFeatureEnabled("feature_new_room_list"); } - public static addListener(handler: () => void) { + public static addListener(handler: () => void): RoomListStoreTempToken { if (RoomListStoreTempProxy.isUsingNewStore()) { - return RoomListStore.instance.on(UPDATE_EVENT, handler); + const offFn = () => RoomListStore.instance.off(UPDATE_EVENT, handler); + RoomListStore.instance.on(UPDATE_EVENT, handler); + return new RoomListStoreTempToken(offFn); } else { - return OldRoomListStore.addListener(handler); + const token = OldRoomListStore.addListener(handler); + return new RoomListStoreTempToken(() => token.remove()); } } @@ -47,3 +50,13 @@ export class RoomListStoreTempProxy { } } } + + +export class RoomListStoreTempToken { + constructor(private offFn: () => void) { + } + + public remove(): void { + this.offFn(); + } +}