armisa-models
Version:
models of armisa!
33 lines (28 loc) • 1.1 kB
text/typescript
//test not ignore lazy function and I commented for other day to fix it
// import { lazy } from "react";
import { MainStateManager } from "./MainStateManager";
export type ILazyLoad = { pageKey: string, path: Promise<any> };
export class LazyLoadFactory {
constructor(
public mainStateManager: MainStateManager,
) { }
public pages: ILazyLoad[] = [];
public add = (key: string, path: Promise<any>) => {
const find = this.pages.find(i => i.pageKey === key);
if (find) {
find.path = path;
} else {
this.pages.push({ pageKey: key, path });
}
}
public get = (key: string): React.LazyExoticComponent<React.ComponentType<any>> => {
const find = this.pages.find(i => i.pageKey === key);
if (find) {
throw Error(`can not find any page key : ${key}`);
// return lazy(() => find.path)
} else {
console.error(`can not find any page key : ${key}`);
throw Error(`can not find any page key : ${key}`);
}
}
}