Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): apploader only emits the latest result #2606

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/thin-baboons-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@equinor/fusion-framework-cli': patch
---

### Modified Files

`AppLoader.tsx`

### Changes

- Added import for last operator from rxjs/operators.
- Updated the initialize subscription to use the last operator.
72 changes: 39 additions & 33 deletions packages/cli/src/bin/dev-portal/AppLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef, useState } from 'react';

import { Subscription } from 'rxjs';
import { last } from 'rxjs/operators';

import { useFramework } from '@equinor/fusion-framework-react';

Expand Down Expand Up @@ -52,39 +53,44 @@ export const AppLoader = (props: { readonly appKey: string }) => {

/** make sure that initialize is canceled and disposed if current app changes */
subscription.add(
currentApp?.initialize().subscribe({
next: ({ manifest, script, config }) => {
/** generate basename for application */
const [basename] = window.location.pathname.match(
/\/?apps\/[a-z|-]+(\/)?/g,
) ?? [''];

/** create a 'private' element for the application */
const el = document.createElement('div');
if (!ref.current) {
throw Error('Missing application mounting point');
}

ref.current.appendChild(el);

/** extract render callback function from javascript module */
const render = script.renderApp ?? script.default;

/** add application teardown to current render effect teardown */
subscription.add(render(el, { fusion, env: { basename, config, manifest } }));

/** remove app element when application unmounts */
subscription.add(() => el.remove());
},
complete: () => {
/** flag that application is no longer loading */
setLoading(false);
},
error: (err) => {
/** set error if initialization of application fails */
setError(err);
},
}),
currentApp
?.initialize()
.pipe(last())
.subscribe({
next: ({ manifest, script, config }) => {
/** generate basename for application */
const [basename] = window.location.pathname.match(
/\/?apps\/[a-z|-]+(\/)?/g,
) ?? [''];

/** create a 'private' element for the application */
const el = document.createElement('div');
if (!ref.current) {
throw Error('Missing application mounting point');
}

ref.current.appendChild(el);

/** extract render callback function from javascript module */
const render = script.renderApp ?? script.default;

/** add application teardown to current render effect teardown */
subscription.add(
render(el, { fusion, env: { basename, config, manifest } }),
);

/** remove app element when application unmounts */
subscription.add(() => el.remove());
},
complete: () => {
/** flag that application is no longer loading */
setLoading(false);
},
error: (err) => {
/** set error if initialization of application fails */
setError(err);
},
}),
);

/** teardown application when hook unmounts */
Expand Down