@equinor/fusion-framework-module-app 2.5.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { OperatorFunction } from 'rxjs';
5
5
  import { EventModule } from '@equinor/fusion-framework-module-event';
6
6
  import { AnyModule, ModuleType } from '@equinor/fusion-framework-module';
7
7
  import { AppBundleStateInitial } from './types';
8
- import '../events';
8
+ import './events';
9
9
  export declare function filterEmpty<T>(): OperatorFunction<T | null | undefined, T>;
10
10
  export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> {
11
11
  #private;
@@ -21,7 +21,11 @@ export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown
21
21
  provider: AppModuleProvider;
22
22
  event?: ModuleType<EventModule>;
23
23
  });
24
- initialize(): Observable<[AppManifest, AppScriptModule, AppConfig]>;
24
+ initialize(): Observable<{
25
+ manifest: AppManifest;
26
+ script: AppScriptModule;
27
+ config: AppConfig;
28
+ }>;
25
29
  loadConfig(): void;
26
30
  loadManifest(): void;
27
31
  loadAppModule(allow_cache?: boolean): Promise<void>;
@@ -19,6 +19,10 @@ declare const createActions: () => {
19
19
  failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
20
20
  };
21
21
  setInstance: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance<unknown>], AppModulesInstance<unknown>, "set_instance", never, never>;
22
+ initialize: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[], null, "initialize_app::request", never, never> & {
23
+ success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[], null, "initialize_app::success", never, never>;
24
+ failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "initialize_app::failure", never, never>;
25
+ };
22
26
  };
23
27
  export declare const actions: {
24
28
  setManifest: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "set_manifest", never, {
@@ -39,6 +43,10 @@ export declare const actions: {
39
43
  failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
40
44
  };
41
45
  setInstance: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance<unknown>], AppModulesInstance<unknown>, "set_instance", never, never>;
46
+ initialize: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[], null, "initialize_app::request", never, never> & {
47
+ success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[], null, "initialize_app::success", never, never>;
48
+ failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "initialize_app::failure", never, never>;
49
+ };
42
50
  };
43
51
  export type ActionBuilder = ReturnType<typeof createActions>;
44
52
  export type ActionMap = ActionInstanceMap<ActionBuilder>;
@@ -0,0 +1,28 @@
1
+ import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
2
+ import type { App } from './App';
3
+ import type { AppConfig, AppManifest, AppModulesInstance } from '../types';
4
+ export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEventInit<TDetail & {
5
+ appKey: string;
6
+ }, App>;
7
+ declare module '@equinor/fusion-framework-module-event' {
8
+ interface FrameworkEventMap {
9
+ onAppModulesLoaded: FrameworkEvent<AppEventEventInit<{
10
+ modules: AppModulesInstance;
11
+ }>>;
12
+ onAppManifestLoaded: FrameworkEvent<AppEventEventInit<{
13
+ manifest: AppManifest;
14
+ }>>;
15
+ onAppConfigLoaded: FrameworkEvent<AppEventEventInit<{
16
+ config: AppConfig;
17
+ }>>;
18
+ onAppScriptLoaded: FrameworkEvent<AppEventEventInit<{
19
+ manifest: AppManifest;
20
+ }>>;
21
+ onAppInitialize: FrameworkEvent<AppEventEventInit>;
22
+ onAppInitialized: FrameworkEvent<AppEventEventInit>;
23
+ onAppInitializeFailed: FrameworkEvent<AppEventEventInit<{
24
+ error: unknown;
25
+ }>>;
26
+ onAppDispose: FrameworkEvent<AppEventEventInit>;
27
+ }
28
+ }
@@ -0,0 +1,3 @@
1
+ import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
2
+ import type { AppConfigBuilderCallback } from './AppConfigBuilder';
3
+ export declare const enableAppModule: (configurator: IModulesConfigurator<any, any>, builder?: AppConfigBuilderCallback) => void;
@@ -1,22 +1,11 @@
1
- import { AnyModule } from '@equinor/fusion-framework-module';
2
1
  import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
3
2
  import { App } from './app/App';
4
- import AppModuleProvider from './AppModuleProvider';
5
- import { AppModulesInstance } from './types';
6
- type AppModulesLoadedEventInit<TModules extends Array<AnyModule> | unknown = unknown> = FrameworkEventInit<{
7
- appKey: string;
8
- modules: AppModulesInstance<TModules>;
9
- }>;
10
- export declare class AppModulesLoadedEvent<TModules extends Array<AnyModule> | unknown = unknown> extends FrameworkEvent<AppModulesLoadedEventInit<TModules>> {
11
- constructor(appKey: string, modules: AppModulesInstance<TModules>, init?: Omit<AppModulesLoadedEventInit<TModules>, 'detail'>);
12
- }
3
+ import './app/events';
13
4
  declare module '@equinor/fusion-framework-module-event' {
14
5
  interface FrameworkEventMap {
15
- onAppModulesLoaded: AppModulesLoadedEvent;
16
6
  onCurrentAppChanged: FrameworkEvent<FrameworkEventInit<{
17
7
  next?: App;
18
8
  previous?: App;
19
- }, AppModuleProvider>>;
9
+ }>>;
20
10
  }
21
11
  }
22
- export {};
@@ -3,4 +3,5 @@ export { AppModuleProvider } from './AppModuleProvider';
3
3
  export { App } from './app/App';
4
4
  export * from './events';
5
5
  export * from './types';
6
- export { default, AppModule, module, moduleKey, enableAppModule } from './module';
6
+ export { enableAppModule } from './enable-app-module';
7
+ export { default, AppModule, module, moduleKey } from './module';
@@ -1,11 +1,10 @@
1
- import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
1
+ import { Module } from '@equinor/fusion-framework-module';
2
2
  import { ModuleDeps } from './types';
3
3
  import { IAppConfigurator } from './AppConfigurator';
4
4
  import { AppModuleProvider } from './AppModuleProvider';
5
5
  export declare const moduleKey = "app";
6
6
  export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
7
7
  export declare const module: AppModule;
8
- export declare const enableAppModule: (configurator: IModulesConfigurator<any, any>) => void;
9
8
  export default module;
10
9
  declare module '@equinor/fusion-framework-module' {
11
10
  interface Modules {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-app",
3
- "version": "2.5.0",
3
+ "version": "2.7.1",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
@@ -45,5 +45,5 @@
45
45
  "@equinor/fusion-framework-module-service-discovery": "^4.0.8",
46
46
  "typescript": "^4.9.3"
47
47
  },
48
- "gitHead": "e5668331df89b0ef6ef6175ea1908d4aeb772544"
48
+ "gitHead": "056c03a474079c018082339051755ab150db113d"
49
49
  }
package/src/app/App.ts CHANGED
@@ -18,7 +18,7 @@ import { createState } from './create-state';
18
18
  import { actions, Actions } from './actions';
19
19
  import { AppBundleState, AppBundleStateInitial } from './types';
20
20
 
21
- import '../events';
21
+ import './events';
22
22
 
23
23
  // TODO - move globally
24
24
  export function filterEmpty<T>(): OperatorFunction<T | null | undefined, T> {
@@ -87,12 +87,17 @@ export class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unkno
87
87
  this.#state = createState(value, args.provider);
88
88
 
89
89
  const { appKey } = value;
90
+ const { event } = args;
90
91
 
91
- const subscriptions = new Subscription();
92
+ event && this.#registerEvents(event);
92
93
 
93
- if (args.event) {
94
+ const subscriptions = new Subscription();
95
+ if (event) {
96
+ subscriptions.add(() => {
97
+ event.dispatchEvent('onAppDispose', { detail: { appKey } });
98
+ });
94
99
  subscriptions.add(
95
- args.event.addEventListener('onAppModulesLoaded', (e) => {
100
+ event.addEventListener('onAppModulesLoaded', (e) => {
96
101
  if (e.detail.appKey === appKey) {
97
102
  this.#state.next(actions.setInstance(e.detail.modules));
98
103
  }
@@ -101,16 +106,104 @@ export class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unkno
101
106
  }
102
107
 
103
108
  this.dispose = () => {
109
+ subscriptions?.unsubscribe();
104
110
  if (this.#state.value.instance) {
111
+ /** tear down modules of application */
105
112
  this.#state.value.instance.dispose();
106
113
  }
107
- subscriptions.unsubscribe();
108
114
  this.#state.complete();
109
115
  };
110
116
  }
111
117
 
112
- public initialize(): Observable<[AppManifest, AppScriptModule, AppConfig]> {
113
- return combineLatest([this.getManifest(), this.getAppModule(), this.getConfig()]);
118
+ #registerEvents(event: ModuleType<EventModule>): void {
119
+ const { appKey } = this;
120
+
121
+ this.#state.addEffect(actions.fetchManifest.success.type, (action) => {
122
+ event.dispatchEvent('onAppManifestLoaded', {
123
+ detail: { appKey, manifest: action.payload },
124
+ source: this,
125
+ });
126
+ });
127
+
128
+ this.#state.addEffect(actions.fetchConfig.success.type, (action) => {
129
+ event.dispatchEvent('onAppConfigLoaded', {
130
+ detail: { appKey, manifest: action.payload },
131
+ source: this,
132
+ });
133
+ });
134
+
135
+ this.#state.addEffect(actions.importApp.success.type, (action) => {
136
+ event.dispatchEvent('onAppScriptLoaded', {
137
+ detail: { appKey, manifest: action.payload },
138
+ source: this,
139
+ });
140
+ });
141
+
142
+ this.#state.addEffect(actions.initialize.type, () => {
143
+ event.dispatchEvent('onAppInitialize', {
144
+ detail: { appKey },
145
+ source: this,
146
+ });
147
+ });
148
+
149
+ this.#state.addEffect(actions.initialize.success.type, () => {
150
+ event.dispatchEvent('onAppInitialized', {
151
+ detail: { appKey },
152
+ source: this,
153
+ });
154
+ });
155
+
156
+ this.#state.addEffect(actions.initialize.failure.type, ({ payload }) => {
157
+ event.dispatchEvent('onAppInitializeFailed', {
158
+ detail: { appKey, error: payload },
159
+ source: this,
160
+ });
161
+ });
162
+ }
163
+
164
+ /**
165
+ * The initializing request won`t trigger until subscribing to the returned observable
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * app.initialize().subscribe({
170
+ * next: (value) => {
171
+ * value.script.render(el, ...);
172
+ * },
173
+ * error: (err) => console.error('failed to load application', err),
174
+ * complete: () => setInitializingApp(false)
175
+ * })
176
+ * ```
177
+ */
178
+ public initialize(): Observable<{
179
+ manifest: AppManifest;
180
+ script: AppScriptModule;
181
+ config: AppConfig;
182
+ }> {
183
+ return new Observable((observer) => {
184
+ this.#state.next(actions.initialize());
185
+ observer.add(
186
+ combineLatest([
187
+ this.getManifest(),
188
+ this.getAppModule(),
189
+ this.getConfig(),
190
+ ]).subscribe({
191
+ next: ([manifest, script, config]) =>
192
+ observer.next({
193
+ manifest,
194
+ script,
195
+ config,
196
+ }),
197
+ error: (err) => {
198
+ observer.error(err), this.#state.next(actions.initialize.failure(err));
199
+ },
200
+ complete: () => {
201
+ this.#state.next(actions.initialize.success());
202
+ observer.complete();
203
+ },
204
+ })
205
+ );
206
+ });
114
207
  }
115
208
 
116
209
  public loadConfig() {
@@ -40,6 +40,13 @@ const createActions = () => ({
40
40
  setInstance: createAction('set_instance', (instance: AppModulesInstance) => ({
41
41
  payload: instance,
42
42
  })),
43
+
44
+ initialize: createAsyncAction(
45
+ 'initialize_app',
46
+ () => ({ payload: null }),
47
+ () => ({ payload: null }),
48
+ (error: unknown) => ({ payload: error })
49
+ ),
43
50
  });
44
51
 
45
52
  export const actions = createActions();
@@ -0,0 +1,67 @@
1
+ import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
2
+
3
+ import type { App } from './App';
4
+
5
+ import type { AppConfig, AppManifest, AppModulesInstance } from '../types';
6
+
7
+ /** base event type for applications */
8
+ export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown = unknown> =
9
+ FrameworkEventInit<
10
+ /** additional event details and key of target event */
11
+ TDetail & { appKey: string },
12
+ /** source of the event */
13
+ App
14
+ >;
15
+
16
+ declare module '@equinor/fusion-framework-module-event' {
17
+ interface FrameworkEventMap {
18
+ /** fired when the application has initiated its modules */
19
+ onAppModulesLoaded: FrameworkEvent<
20
+ AppEventEventInit<{
21
+ /** initiated modules for application */
22
+ modules: AppModulesInstance;
23
+ }>
24
+ >;
25
+
26
+ /** fired when the application has loaded corresponding manifest */
27
+ onAppManifestLoaded: FrameworkEvent<
28
+ AppEventEventInit<{
29
+ manifest: AppManifest;
30
+ }>
31
+ >;
32
+
33
+ /** fired when the application has loaded corresponding config */
34
+ onAppConfigLoaded: FrameworkEvent<
35
+ AppEventEventInit<{
36
+ config: AppConfig;
37
+ }>
38
+ >;
39
+
40
+ /** fired when the application has loaded corresponding javascript module */
41
+ onAppScriptLoaded: FrameworkEvent<
42
+ AppEventEventInit<{
43
+ manifest: AppManifest;
44
+ }>
45
+ >;
46
+
47
+ /** fired before application loads manifest, config and script */
48
+ onAppInitialize: FrameworkEvent<AppEventEventInit>;
49
+
50
+ /**
51
+ * fired after application has loaded manifest, config and script
52
+ *
53
+ * __note:__ not fired until all loaders has settled (last emit)
54
+ */
55
+ onAppInitialized: FrameworkEvent<AppEventEventInit>;
56
+
57
+ /** fired when application fails to load either manifest, config and script */
58
+ onAppInitializeFailed: FrameworkEvent<
59
+ AppEventEventInit<{
60
+ error: unknown;
61
+ }>
62
+ >;
63
+
64
+ /** fired when the application is disposed (unmounts) */
65
+ onAppDispose: FrameworkEvent<AppEventEventInit>;
66
+ }
67
+ }
@@ -0,0 +1,21 @@
1
+ import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
2
+ import type { AppConfigBuilderCallback } from './AppConfigBuilder';
3
+
4
+ import { module } from './module';
5
+
6
+ /**
7
+ * Method for enabling the Service module
8
+ * @param configurator - configuration object
9
+ */
10
+ export const enableAppModule = (
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ configurator: IModulesConfigurator<any, any>,
13
+ builder?: AppConfigBuilderCallback
14
+ ): void => {
15
+ configurator.addConfig({
16
+ module,
17
+ configure: (appConfigurator) => {
18
+ builder && appConfigurator.addConfigBuilder(builder);
19
+ },
20
+ });
21
+ };
package/src/events.ts CHANGED
@@ -1,34 +1,18 @@
1
- import { AnyModule } from '@equinor/fusion-framework-module';
2
-
3
1
  import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
4
2
  import { App } from './app/App';
5
- import AppModuleProvider from './AppModuleProvider';
6
-
7
- import { AppModulesInstance } from './types';
8
-
9
- type AppModulesLoadedEventInit<TModules extends Array<AnyModule> | unknown = unknown> =
10
- FrameworkEventInit<{
11
- appKey: string;
12
- modules: AppModulesInstance<TModules>;
13
- }>;
14
3
 
15
- export class AppModulesLoadedEvent<
16
- TModules extends Array<AnyModule> | unknown = unknown
17
- > extends FrameworkEvent<AppModulesLoadedEventInit<TModules>> {
18
- constructor(
19
- appKey: string,
20
- modules: AppModulesInstance<TModules>,
21
- init?: Omit<AppModulesLoadedEventInit<TModules>, 'detail'>
22
- ) {
23
- super('onAppModulesLoaded', { ...init, detail: { appKey, modules } });
24
- }
25
- }
4
+ import './app/events';
26
5
 
27
6
  declare module '@equinor/fusion-framework-module-event' {
28
7
  interface FrameworkEventMap {
29
- onAppModulesLoaded: AppModulesLoadedEvent;
8
+ /** fired when the current selected application changes */
30
9
  onCurrentAppChanged: FrameworkEvent<
31
- FrameworkEventInit<{ next?: App; previous?: App }, AppModuleProvider>
10
+ FrameworkEventInit<{
11
+ /** current application */
12
+ next?: App;
13
+ /** previous application */
14
+ previous?: App;
15
+ }>
32
16
  >;
33
17
  }
34
18
  }
package/src/index.ts CHANGED
@@ -11,4 +11,6 @@ export { App } from './app/App';
11
11
  export * from './events';
12
12
  export * from './types';
13
13
 
14
- export { default, AppModule, module, moduleKey, enableAppModule } from './module';
14
+ export { enableAppModule } from './enable-app-module';
15
+
16
+ export { default, AppModule, module, moduleKey } from './module';
package/src/module.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
1
+ import { Module } from '@equinor/fusion-framework-module';
2
2
  import { ModuleDeps } from './types';
3
3
 
4
4
  import { IAppConfigurator, AppConfigurator } from './AppConfigurator';
@@ -21,11 +21,6 @@ export const module: AppModule = {
21
21
  },
22
22
  };
23
23
 
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- export const enableAppModule = (configurator: IModulesConfigurator<any, any>) => {
26
- configurator.addConfig({ module });
27
- };
28
-
29
24
  export default module;
30
25
 
31
26
  declare module '@equinor/fusion-framework-module' {