App
9/8/25About 1 min
This module purpose is:
This module is mainly developed for helping portal for keeping track of selected application and loading of application.
Application instance
Initialize
when calling initialize
, it might emit multiple time, since manifest and config has cache.
How to only use settle values
// Observable
app.initialize().pipe(last());
// Async
await lastValueFrom(app.initialize());
Manifest
Meta data description of application, loaded from the Fusion Application Store
Config
Configuration for the application
Script Modules
imported javascript script modules
Instance
Collection of initialized modules of the application
Configuration
simple
export const configure = (configurator) => {
enableAppModule(configurator);
}
custom
const manifestMapper = (value: any): AppManifest => {
const { appKey, name, entry, version } = value;
return { appKey, name, entry, version };
}
export const configure = (configurator) => {
enableAppModule(configurator, async(builder) => {
const httpProvider = await builder.requireInstance('http');
const appClient = httpProvider.createClient('app-api-client');
builder.setAppClient(() => {
/** callback for fetching an applications */
getAppManifest: ({ appKey: string }) => appClient.json$(
`/api/app/${appKey}`,
{ selector: async(x) => manifestMapper(await res.json()) }
),
/** callback for fetching all applications */
getAppManifests: () => appClient.json$(
`/api/apps`,
{ selector: async(x) => (await res.json()).map(manifestMapper) }
),
/** callback for fetching application config */
getAppConfig: ({ appKey: string }) => appClient.json$(
`/api/app/${appKey}/config`,
),
});
});
}
Events
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
import type { App } from './app/App';
import './app/events';
declare module '@equinor/fusion-framework-module-event' {
interface FrameworkEventMap {
/** fired when the current selected application changes */
onCurrentAppChanged: FrameworkEvent<
FrameworkEventInit<{
/** current application */
next?: App;
/** previous application */
previous?: App;
}>
>;
}
}
App
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
import type { App } from './App';
import type {
AppConfig,
AppManifest,
AppModulesInstance,
AppScriptModule,
AppSettings,
} from '../types';
/** base event type for applications */
export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown = unknown> =
FrameworkEventInit<
/** additional event details and key of target event */
TDetail & { appKey: string },
/** source of the event */
App
>;
export type AppEvent<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEvent<
AppEventEventInit<TDetail>
>;
export type AppEventFailure = FrameworkEvent<
AppEventEventInit<{
error: AppConfig;
}>
>;
declare module '@equinor/fusion-framework-module-event' {
interface FrameworkEventMap {
/** fired when the application has initiated its modules */
onAppModulesLoaded: AppEvent<{
/** initiated modules for application */
modules: AppModulesInstance;
}>;
onAppManifestLoad: AppEvent;
/** fired when the application has loaded corresponding manifest */
onAppManifestLoaded: AppEvent<{
manifest: AppManifest;
}>;
onAppManifestFailure: AppEventFailure;
onAppConfigLoad: AppEvent;
/** fired when the application has loaded corresponding config */
onAppConfigLoaded: AppEvent<{
config: AppConfig;
}>;
onAppConfigFailure: AppEventFailure;
onAppSettingsLoad: AppEvent;
/** fired when the application has loaded corresponding settings */
onAppSettingsLoaded: AppEvent<{
settings: AppSettings;
}>;
onAppSettingsFailure: AppEventFailure;
onAppSettingsUpdate: AppEvent;
onAppSettingsUpdated: AppEvent<{
settings: AppSettings;
}>;
onAppSettingsUpdateFailure: AppEventFailure;
/** fired when the application has loaded corresponding javascript module */
onAppScriptLoad: AppEvent;
onAppScriptLoaded: AppEvent<{
script: AppScriptModule;
}>;
onAppScriptFailure: AppEventFailure;
/** fired before application loads manifest, config and script */
onAppInitialize: AppEvent;
/**
* fired after application has loaded manifest, config and script
*
* __note:__ not fired until all loaders has settled (last emit)
*/
onAppInitialized: AppEvent;
/** fired when application fails to load either manifest, config and script */
onAppInitializeFailure: AppEventFailure;
/** fired when the application is disposed (unmounts) */
onAppDispose: FrameworkEvent<AppEventEventInit>;
}
}
Examples
Apploader
File not found