@equinor/fusion-framework-module
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -6,2 +6,11 @@ # Change Log | ||
## 1.2.0 (2022-09-20) | ||
### Features | ||
* **module:** add has module check ([e32cf7b](https://github.com/equinor/fusion-framework/commit/e32cf7b751854ae8e306bb1d6a84260099752714)) | ||
## [1.1.3](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@1.1.2...@equinor/fusion-framework-module@1.1.3) (2022-09-14) | ||
@@ -8,0 +17,0 @@ |
@@ -103,2 +103,3 @@ import { BehaviorSubject, firstValueFrom, from, lastValueFrom, throwError } from 'rxjs'; | ||
const instance$ = new BehaviorSubject({}); | ||
const hasModule = (name) => moduleNames.includes(name); | ||
const requireInstance = (name, wait = 60) => { | ||
@@ -123,3 +124,8 @@ if (!moduleNames.includes(name)) { | ||
logger.debug(`🚀 initializing ${logger.formatModuleName(module)}`); | ||
return from(Promise.resolve(module.initialize({ ref, config: config[key], requireInstance }))).pipe(map((instance) => { | ||
return from(Promise.resolve(module.initialize({ | ||
ref, | ||
config: config[key], | ||
requireInstance, | ||
hasModule, | ||
}))).pipe(map((instance) => { | ||
logger.debug(`🚀 initialized ${logger.formatModuleName(module)}`); | ||
@@ -126,0 +132,0 @@ return [key, instance]; |
@@ -0,1 +1,7 @@ | ||
declare type ModuleInitializerArgs<TConfig, TDeps extends Array<AnyModule>> = { | ||
ref?: any; | ||
config: TConfig; | ||
requireInstance: <TKey extends keyof ModulesInstanceType<TDeps>>(name: TKey, wait?: number) => Promise<ModulesInstanceType<TDeps>[TKey]>; | ||
hasModule: ((key: keyof ModulesInstanceType<TDeps>) => boolean) | ((key: string) => boolean); | ||
}; | ||
export interface Module<TKey extends string, TType, TConfig, TDeps extends Array<AnyModule> = []> { | ||
@@ -5,7 +11,3 @@ name: TKey; | ||
postConfigure?: (config: Record<TKey, TConfig> & ModulesConfigType<ModulesType<TDeps>>) => void | Promise<void>; | ||
initialize: (args: { | ||
ref?: any; | ||
config: TConfig; | ||
requireInstance: <TKey extends keyof ModulesInstanceType<TDeps>>(name: TKey, wait?: number) => Promise<ModulesInstanceType<TDeps>[TKey]>; | ||
}) => TType | Promise<TType>; | ||
initialize: (args: ModuleInitializerArgs<TConfig, TDeps>) => TType | Promise<TType>; | ||
postInitialize?: (args: { | ||
@@ -12,0 +14,0 @@ ref?: any; |
{ | ||
"name": "@equinor/fusion-framework-module", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -31,3 +31,3 @@ "main": "dist/esm/index.js", | ||
}, | ||
"gitHead": "4e92ef5173981f4e43bad9a2a2e53fb3f71da7a1" | ||
"gitHead": "2cd29e53f0f29582cdf98b18699d6aa0f171f7fe" | ||
} |
@@ -203,2 +203,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const hasModule = (name: string) => moduleNames.includes(name); | ||
const requireInstance = < | ||
@@ -247,5 +249,10 @@ TKey extends keyof ModulesInstanceType<CombinedModules<T, TModules>> | ||
Promise.resolve( | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
module.initialize({ ref, config: config[key], requireInstance }) | ||
module.initialize({ | ||
ref, | ||
config: config[key as keyof typeof config], | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
requireInstance, | ||
hasModule, | ||
}) | ||
) | ||
@@ -252,0 +259,0 @@ ).pipe( |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
type ModuleInitializerArgs<TConfig, TDeps extends Array<AnyModule>> = { | ||
ref?: any; | ||
config: TConfig; | ||
requireInstance: <TKey extends keyof ModulesInstanceType<TDeps>>( | ||
name: TKey, | ||
wait?: number | ||
) => Promise<ModulesInstanceType<TDeps>[TKey]>; | ||
hasModule: ((key: keyof ModulesInstanceType<TDeps>) => boolean) | ((key: string) => boolean); | ||
}; | ||
export interface Module<TKey extends string, TType, TConfig, TDeps extends Array<AnyModule> = []> { | ||
@@ -9,10 +19,3 @@ name: TKey; | ||
) => void | Promise<void>; | ||
initialize: (args: { | ||
ref?: any; | ||
config: TConfig; | ||
requireInstance: <TKey extends keyof ModulesInstanceType<TDeps>>( | ||
name: TKey, | ||
wait?: number | ||
) => Promise<ModulesInstanceType<TDeps>[TKey]>; | ||
}) => TType | Promise<TType>; | ||
initialize: (args: ModuleInitializerArgs<TConfig, TDeps>) => TType | Promise<TType>; | ||
postInitialize?: (args: { | ||
@@ -19,0 +22,0 @@ ref?: any; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
812
113968