Skip to content

Commit

Permalink
Add getExt to ExtensionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
tschicke committed Aug 8, 2023
1 parent 4e0d739 commit 6ccb190
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ExtensionApi {

export interface ExtensionContext {
api: ExtensionApi;
getExt: (name: string) => Promise<ExtensionData>;
}

/**
Expand Down Expand Up @@ -121,12 +122,16 @@ export class ExtensionData implements Required<ExtensionModule> {
}
}

async function loadExtensionModule(name: string): Promise<ExtensionData> {
async function loadExtensionModule(
name: string,
getExtension: (name: string) => Promise<ExtensionData>,
): Promise<ExtensionData> {
const url = urlFor(`extension_js_module/${name}.js`, undefined, false);
const mod = await (import(url) as Promise<{ default?: ExtensionModule }>);
if (typeof mod.default === "object") {
const context: ExtensionContext = {
api: new ExtensionApi(name),
getExt: getExtension,
};
return new ExtensionData(context, mod.default);
}
Expand All @@ -144,7 +149,7 @@ async function getExt(name: string): Promise<ExtensionData> {
if (loaded_ext) {
return loaded_ext;
}
const ext = loadExtensionModule(name);
const ext = loadExtensionModule(name, getExt);
loaded_extensions.set(name, ext);
(await ext).init();
return ext;
Expand Down

0 comments on commit 6ccb190

Please sign in to comment.