Merge pull request #4934 from matrix-org/travis/room-list/perf/layout
Move list layout management to its own store
This commit is contained in:
commit
8aa2ed0c8b
5 changed files with 103 additions and 40 deletions
73
src/stores/room-list/RoomListLayoutStore.ts
Normal file
73
src/stores/room-list/RoomListLayoutStore.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { TagID } from "./models";
|
||||
import { ListLayout } from "./ListLayout";
|
||||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||
import { ActionPayload } from "../../dispatcher/payloads";
|
||||
|
||||
interface IState {}
|
||||
|
||||
export default class RoomListLayoutStore extends AsyncStoreWithClient<IState> {
|
||||
private static internalInstance: RoomListLayoutStore;
|
||||
|
||||
private readonly layoutMap = new Map<TagID, ListLayout>();
|
||||
|
||||
constructor() {
|
||||
super(defaultDispatcher);
|
||||
}
|
||||
|
||||
public static get instance(): RoomListLayoutStore {
|
||||
if (!RoomListLayoutStore.internalInstance) {
|
||||
RoomListLayoutStore.internalInstance = new RoomListLayoutStore();
|
||||
}
|
||||
return RoomListLayoutStore.internalInstance;
|
||||
}
|
||||
|
||||
public ensureLayoutExists(tagId: TagID) {
|
||||
if (!this.layoutMap.has(tagId)) {
|
||||
this.layoutMap.set(tagId, new ListLayout(tagId));
|
||||
}
|
||||
}
|
||||
|
||||
public getLayoutFor(tagId: TagID): ListLayout {
|
||||
if (!this.layoutMap.has(tagId)) {
|
||||
this.layoutMap.set(tagId, new ListLayout(tagId));
|
||||
}
|
||||
return this.layoutMap.get(tagId);
|
||||
}
|
||||
|
||||
// Note: this primarily exists for debugging, and isn't really intended to be used by anything.
|
||||
public async resetLayouts() {
|
||||
console.warn("Resetting layouts for room list");
|
||||
for (const layout of this.layoutMap.values()) {
|
||||
layout.reset();
|
||||
}
|
||||
}
|
||||
|
||||
protected async onNotReady(): Promise<any> {
|
||||
// On logout, clear the map.
|
||||
this.layoutMap.clear();
|
||||
}
|
||||
|
||||
// We don't need this function, but our contract says we do
|
||||
protected async onAction(payload: ActionPayload): Promise<any> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
window.mx_RoomListLayoutStore = RoomListLayoutStore.instance;
|
|
@ -32,6 +32,7 @@ import { Algorithm, LIST_UPDATED_EVENT } from "./algorithms/Algorithm";
|
|||
import { EffectiveMembership, getEffectiveMembership } from "./membership";
|
||||
import { ListLayout } from "./ListLayout";
|
||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||
import RoomListLayoutStore from "./RoomListLayoutStore";
|
||||
|
||||
interface IState {
|
||||
tagsEnabled?: boolean;
|
||||
|
@ -50,6 +51,7 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
private algorithm = new Algorithm();
|
||||
private filterConditions: IFilterCondition[] = [];
|
||||
private tagWatcher = new TagWatcher(this);
|
||||
private layoutMap: Map<TagID, ListLayout> = new Map<TagID, ListLayout>();
|
||||
|
||||
private readonly watchedSettings = [
|
||||
'feature_custom_tags',
|
||||
|
@ -416,6 +418,8 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
for (const tagId of OrderedDefaultTagIDs) {
|
||||
sorts[tagId] = this.calculateTagSorting(tagId);
|
||||
orders[tagId] = this.calculateListOrder(tagId);
|
||||
|
||||
RoomListLayoutStore.instance.ensureLayoutExists(tagId);
|
||||
}
|
||||
|
||||
if (this.state.tagsEnabled) {
|
||||
|
@ -434,15 +438,6 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
this.emit(LISTS_UPDATE_EVENT, this);
|
||||
}
|
||||
|
||||
// Note: this primarily exists for debugging, and isn't really intended to be used by anything.
|
||||
public async resetLayouts() {
|
||||
console.warn("Resetting layouts for room list");
|
||||
for (const tagId of Object.keys(this.orderedLists)) {
|
||||
new ListLayout(tagId).reset();
|
||||
}
|
||||
await this.regenerateAllLists();
|
||||
}
|
||||
|
||||
public addFilter(filter: IFilterCondition): void {
|
||||
// TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14035
|
||||
console.log("Adding filter condition:", filter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue