load features at startup and pass them along in all view models

This commit is contained in:
Bruno Windels 2023-02-09 11:52:39 +01:00
parent c4944599cf
commit f65b43f612
2 changed files with 10 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import type {Navigation} from "./navigation/Navigation";
import type {SegmentType} from "./navigation/index";
import type {IURLRouter} from "./navigation/URLRouter";
import type { ITimeFormatter } from "../platform/types/types";
import type { FeatureSet } from "../features";
export type Options<T extends object = SegmentType> = {
platform: Platform;
@ -37,6 +38,7 @@ export type Options<T extends object = SegmentType> = {
urlRouter: IURLRouter<T>;
navigation: Navigation<T>;
emitChange?: (params: any) => void;
features: FeatureSet
}
@ -142,6 +144,10 @@ export class ViewModel<N extends object = SegmentType, O extends Options<N> = Op
return this._options.urlRouter;
}
get features(): FeatureSet {
return this._options.features;
}
get navigation(): Navigation<N> {
// typescript needs a little help here
return this._options.navigation as unknown as Navigation<N>;

View File

@ -18,6 +18,8 @@ limitations under the License.
// import {RecordRequester, ReplayRequester} from "./matrix/net/request/replay";
import {RootViewModel} from "../../domain/RootViewModel.js";
import {createNavigation, createRouter} from "../../domain/navigation/index";
import {FeatureSet} from "../../features";
// Don't use a default export here, as we use multiple entries during legacy build,
// which does not support default exports,
// see https://github.com/rollup/plugins/tree/master/packages/multi-entry
@ -33,6 +35,7 @@ export async function main(platform) {
// const request = recorder.request;
// window.getBrawlFetchLog = () => recorder.log();
await platform.init();
const features = await FeatureSet.load(platform.settingsStorage);
const navigation = createNavigation();
platform.setNavigation(navigation);
const urlRouter = createRouter({navigation, history: platform.history});
@ -43,6 +46,7 @@ export async function main(platform) {
// so we call it that in the view models
urlRouter: urlRouter,
navigation,
features
});
await vm.load();
platform.createAndMountRootView(vm);