Try to reduce WidgetStore causing downstream problems
This commit is contained in:
parent
f8fe454c59
commit
29780d902c
2 changed files with 14 additions and 5 deletions
|
@ -76,7 +76,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
||||||
this.matrixClient.getRooms().forEach((room: Room) => {
|
this.matrixClient.getRooms().forEach((room: Room) => {
|
||||||
this.loadRoomWidgets(room);
|
this.loadRoomWidgets(room);
|
||||||
});
|
});
|
||||||
this.emit(UPDATE_EVENT);
|
this.emit(UPDATE_EVENT, null); // emit for all rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async onNotReady(): Promise<any> {
|
protected async onNotReady(): Promise<any> {
|
||||||
|
@ -94,7 +94,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
||||||
private onWidgetEchoStoreUpdate = (roomId: string, widgetId: string) => {
|
private onWidgetEchoStoreUpdate = (roomId: string, widgetId: string) => {
|
||||||
this.initRoom(roomId);
|
this.initRoom(roomId);
|
||||||
this.loadRoomWidgets(this.matrixClient.getRoom(roomId));
|
this.loadRoomWidgets(this.matrixClient.getRoom(roomId));
|
||||||
this.emit(UPDATE_EVENT);
|
this.emit(UPDATE_EVENT, roomId);
|
||||||
};
|
};
|
||||||
|
|
||||||
private generateApps(room: Room): IApp[] {
|
private generateApps(room: Room): IApp[] {
|
||||||
|
@ -143,7 +143,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
||||||
const roomId = ev.getRoomId();
|
const roomId = ev.getRoomId();
|
||||||
this.initRoom(roomId);
|
this.initRoom(roomId);
|
||||||
this.loadRoomWidgets(this.matrixClient.getRoom(roomId));
|
this.loadRoomWidgets(this.matrixClient.getRoom(roomId));
|
||||||
this.emit(UPDATE_EVENT);
|
this.emit(UPDATE_EVENT, roomId);
|
||||||
};
|
};
|
||||||
|
|
||||||
public getRoom = (roomId: string) => {
|
public getRoom = (roomId: string) => {
|
||||||
|
|
|
@ -131,7 +131,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||||
this.matrixClient.on("RoomState.events", this.updateRoomFromState);
|
this.matrixClient.on("RoomState.events", this.updateRoomFromState);
|
||||||
this.pinnedRef = SettingsStore.watchSetting("Widgets.pinned", null, this.updateFromSettings);
|
this.pinnedRef = SettingsStore.watchSetting("Widgets.pinned", null, this.updateFromSettings);
|
||||||
this.layoutRef = SettingsStore.watchSetting("Widgets.layout", 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<any> {
|
protected async onNotReady(): Promise<any> {
|
||||||
|
@ -139,7 +139,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||||
|
|
||||||
SettingsStore.unwatchSetting(this.pinnedRef);
|
SettingsStore.unwatchSetting(this.pinnedRef);
|
||||||
SettingsStore.unwatchSetting(this.layoutRef);
|
SettingsStore.unwatchSetting(this.layoutRef);
|
||||||
WidgetStore.instance.off(UPDATE_EVENT, this.updateAllRooms);
|
WidgetStore.instance.off(UPDATE_EVENT, this.updateFromWidgetStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateAllRooms = () => {
|
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) => {
|
private updateRoomFromState = (ev: MatrixEvent) => {
|
||||||
if (ev.getType() !== WIDGET_LAYOUT_EVENT_TYPE) return;
|
if (ev.getType() !== WIDGET_LAYOUT_EVENT_TYPE) return;
|
||||||
const room = this.matrixClient.getRoom(ev.getRoomId());
|
const room = this.matrixClient.getRoom(ev.getRoomId());
|
||||||
|
|
Loading…
Reference in a new issue