Skip to content

Commit

Permalink
refactor: Improve loading logic in LegacyAppContainer, by loading app…
Browse files Browse the repository at this point in the history
… from new app api with proxy
  • Loading branch information
Noggling committed Oct 22, 2024
1 parent 7a89ae3 commit 0b78774
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
* assume if the manifest missing AppComponent or render, that loading is required
*/

if (!AppComponent && !render) {
await this.#loadScript(key);
const manifest = this.#manifests.value[appKey] as unknown as AppManifest;

if (!AppComponent && !render && manifest.build) {
await this.#loadScript(manifest);
}
await new Promise((resolve) => window.requestAnimationFrame(resolve));

const manifest = this.#manifests.value[appKey] as unknown as AppManifest;

const currentApp = appProvider.current;

if (currentApp && currentApp.appKey === appKey) {
Expand Down Expand Up @@ -285,8 +285,9 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
return this.updateComplete;
}

async #loadScript(appKey: string): Promise<void> {
async #loadScript(manifest: AppManifest): Promise<void> {
return new Promise((resolve, reject) => {
const { appKey, build } = manifest;
const script = document.createElement('script');
script.async = true;
script.id = appKey;
Expand All @@ -296,16 +297,15 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
script.addEventListener('load', () => resolve());
script.addEventListener('abort', () => reject());
script.addEventListener('error', () => reject());
// Todo: Fix uri to mach the new structure
script.src = `${window['clientBaseUri']}/api/bundles/${appKey}.js`;
script.src = `/apps-proxy/bundles/apps/${appKey}/${build?.version}/${build?.entryPoint}`;
});
}

#update(): void {
console.log('Updating');
this.#updateTask = new Promise((resolve, reject) => {
this.#updateTask.state = 'pending';
this.#appModules.app.getAllAppManifests().subscribe({
this.#appModules.app.getAppManifests({ filterByCurrentUser: true }).subscribe({
complete: () => {
this.#updateTask.state = 'fulfilled';
this.#lastUpdated = Date.now();
Expand Down

0 comments on commit 0b78774

Please sign in to comment.