mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: add provideFeature/getFeature API
This commit is contained in:
5 files changed
+34
-21
No files matched your search
@@ -18,6 +18,7 @@ export * from './misc/Page';
|
||||
export { initPageLoader } from './hydro';
|
||||
|
||||
const lazyModules = {};
|
||||
const features = {};
|
||||
export default async function load(name: string) {
|
||||
if (window.node_modules[name]) return window.node_modules[name];
|
||||
if (name === 'echarts') return import('echarts');
|
||||
@@ -37,6 +38,15 @@ export default async function load(name: string) {
|
||||
document.body.appendChild(tag);
|
||||
return lazyModules[name];
|
||||
}
|
||||
export async function getFeatures(name: string) {
|
||||
const legacy = Object.keys(window.externalModules).filter((i) => i === name || i.startsWith(`${name}@`));
|
||||
const c = Object.keys(features).filter((i) => i === name || i.startsWith(`${name}@`));
|
||||
return legacy.concat(c);
|
||||
}
|
||||
|
||||
export function provideFeature(name: string, content: string) {
|
||||
features[name] = content;
|
||||
}
|
||||
|
||||
export interface EventMap { }
|
||||
|
||||
|
||||
Reference in new issue
Block a user