From 29780d902cc62a863083ccc8eef6f1d162796721 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 20 Jan 2021 14:44:30 -0700 Subject: [PATCH] Try to reduce WidgetStore causing downstream problems --- src/stores/WidgetStore.ts | 6 +++--- src/stores/widgets/WidgetLayoutStore.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/stores/WidgetStore.ts b/src/stores/WidgetStore.ts index 2f06dfcb80..c53c85dfd5 100644 --- a/src/stores/WidgetStore.ts +++ b/src/stores/WidgetStore.ts @@ -76,7 +76,7 @@ export default class WidgetStore extends AsyncStoreWithClient { this.matrixClient.getRooms().forEach((room: Room) => { this.loadRoomWidgets(room); }); - this.emit(UPDATE_EVENT); + this.emit(UPDATE_EVENT, null); // emit for all rooms } protected async onNotReady(): Promise { @@ -94,7 +94,7 @@ export default class WidgetStore extends AsyncStoreWithClient { private onWidgetEchoStoreUpdate = (roomId: string, widgetId: string) => { this.initRoom(roomId); this.loadRoomWidgets(this.matrixClient.getRoom(roomId)); - this.emit(UPDATE_EVENT); + this.emit(UPDATE_EVENT, roomId); }; private generateApps(room: Room): IApp[] { @@ -143,7 +143,7 @@ export default class WidgetStore extends AsyncStoreWithClient { const roomId = ev.getRoomId(); this.initRoom(roomId); this.loadRoomWidgets(this.matrixClient.getRoom(roomId)); - this.emit(UPDATE_EVENT); + this.emit(UPDATE_EVENT, roomId); }; public getRoom = (roomId: string) => { diff --git a/src/stores/widgets/WidgetLayoutStore.ts b/src/stores/widgets/WidgetLayoutStore.ts index d54cb36a6c..bce684241d 100644 --- a/src/stores/widgets/WidgetLayoutStore.ts +++ b/src/stores/widgets/WidgetLayoutStore.ts @@ -131,7 +131,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore { this.matrixClient.on("RoomState.events", this.updateRoomFromState); this.pinnedRef = SettingsStore.watchSetting("Widgets.pinned", null, this.updateFromSettings); this.layoutRef = SettingsStore.watchSetting("Widgets.layout", null, this.updateFromSettings); - WidgetStore.instance.on(UPDATE_EVENT, this.updateAllRooms); + WidgetStore.instance.on(UPDATE_EVENT, this.updateFromWidgetStore); } protected async onNotReady(): Promise { @@ -139,7 +139,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore { SettingsStore.unwatchSetting(this.pinnedRef); SettingsStore.unwatchSetting(this.layoutRef); - WidgetStore.instance.off(UPDATE_EVENT, this.updateAllRooms); + WidgetStore.instance.off(UPDATE_EVENT, this.updateFromWidgetStore); } private updateAllRooms = () => { @@ -149,6 +149,15 @@ export class WidgetLayoutStore extends ReadyWatchingStore { } }; + private updateFromWidgetStore = (roomId?:string) => { + if (roomId) { + const room = this.matrixClient.getRoom(roomId); + if (room) this.recalculateRoom(room); + } else { + this.updateAllRooms(); + } + }; + private updateRoomFromState = (ev: MatrixEvent) => { if (ev.getType() !== WIDGET_LAYOUT_EVENT_TYPE) return; const room = this.matrixClient.getRoom(ev.getRoomId());