mustard-app
Version:
个人前端微应用建设中。。。
65 lines (50 loc) • 1.96 kB
text/typescript
import App from './app';
import { EventCenterMicroApp } from './communication';
import { MustardApp } from './element';
export type TFunction = (...arg:unknown[]) => unknown
export const AppName = 'mustard-app'; // 元素名
export const LocationPrefix = 'mApp-'; // location path 前缀
export type IApp = App;
export const MainMustardApp = 'main'; // 基座标识(禁用)
export type MustardName = string; // 子应用标识, 不能为 MainMustardApp
export type MustardURL = string; // `http://${string}`|`https://${string}`; // 应用开启地址
// 子应用状态
export enum IAppStatus {
create = 0, // 初始化
loading = 1, // 数据加载中
mount = 2, // dom节点 挂载完成阶段
unmount = 3, // dom节点 卸载
destory = 4, // 销毁应用
error = -100 // 子应用异常
}
export type IAppStatusCN = keyof typeof IAppStatus;
export const APPStAtUSCNKEYS: IAppStatusCN[] = ['create', 'loading', 'mount', 'unmount', 'destory', 'error'];
export interface SpurceValue {
code: string; // 具体代码
isExternal?: boolean; // 是否远程资源
}
export interface IAppConstructor {
name: MustardName;
url: MustardURL;
container: MustardApp;
}
declare global{
interface HTMLElementTagNameMap{
'mustard-app': MustardApp
}
interface Window{
mustardAppInfos: { // 微应用实例
currentReadDocMAppName?: MustardName;
appInstanceMap: Map<MustardName, IApp>; // 当前所有子应用实例
getAppProxyWindow: (appName: MustardName) => IApp['sandbox']['proxyWindow'];
};
// 子应用通讯方法
microApp: EventCenterMicroApp
}
}
export abstract class AMustardApp extends HTMLElement {
url:MustardURL; // 子应用资源地址
name:MustardName; // 子应用标识
// 组件刷新
abstract reload : void;
}