mirror of https://github.com/vector-im/riot-web
Add token.remove() handling to room list temp proxy
Fixes https://github.com/vector-im/riot-web/issues/13930pull/21833/head
parent
fed52f274e
commit
c360800631
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue