feat: add app fof iife
This commit is contained in:
12
src/app.ts
Normal file
12
src/app.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// 当前的功能,把所有的模块注入到windows对象当中
|
||||
import { useConfigKey, useContextKey } from './web-env.ts';
|
||||
import { QueryRouterServer } from '@kevisual/router/browser';
|
||||
|
||||
// bind to window, 必须要的获取全局的环境变量
|
||||
window.useConfigKey = useConfigKey;
|
||||
window.useContextKey = useContextKey;
|
||||
window.QueryRouterServer = QueryRouterServer;
|
||||
|
||||
// bind to window, 获取路由对象
|
||||
useContextKey('app', () => new QueryRouterServer());
|
||||
|
||||
@@ -4,6 +4,7 @@ type GlobalEnv = {
|
||||
name?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
// 从window对象中获取全局的环境变量,如果没有则初始化一个
|
||||
export const useEnv = (initEnv?: GlobalEnv, initKey = 'config') => {
|
||||
const env: GlobalEnv = (window as any)[initKey];
|
||||
const _env = env || initEnv;
|
||||
@@ -17,6 +18,7 @@ export const useEnv = (initEnv?: GlobalEnv, initKey = 'config') => {
|
||||
return window[initKey] as GlobalEnv;
|
||||
};
|
||||
|
||||
// 从全局环境变量中获取指定的key值,如果没有则初始化一个, key不存在,返回Env对象
|
||||
export const useEnvKey = <T = any>(key: string, init?: () => T | null, initKey = 'config'): T => {
|
||||
const _env = useEnv({}, initKey);
|
||||
if (key && _env[key]) {
|
||||
|
||||
Reference in New Issue
Block a user