@squide/firefly 11.0.0 → 12.0.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.
- package/CHANGELOG.md +21 -0
- package/dist/AppRouter.d.ts +0 -1
- package/dist/AppRouter.js +2 -2
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterReducer.d.ts +3 -1
- package/dist/AppRouterReducer.js +27 -4
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.d.ts +13 -0
- package/dist/AppRouterStore.js +158 -0
- package/dist/AppRouterStore.js.map +1 -0
- package/dist/FireflyRuntime.d.ts +2 -0
- package/dist/FireflyRuntime.js +9 -0
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.d.ts +15 -0
- package/dist/{boostrap.js → initializeFirefly.js} +24 -9
- package/dist/initializeFirefly.js.map +1 -0
- package/dist/useAppRouterStore.d.ts +1 -0
- package/dist/useAppRouterStore.js +14 -0
- package/dist/useAppRouterStore.js.map +1 -0
- package/dist/useCanFetchProtectedData.d.ts +2 -0
- package/dist/useCanFetchProtectedData.js +10 -5
- package/dist/useCanFetchProtectedData.js.map +1 -1
- package/package.json +5 -5
- package/src/AppRouter.tsx +1 -4
- package/src/AppRouterReducer.ts +21 -9
- package/src/AppRouterStore.ts +171 -0
- package/src/FireflyRuntime.tsx +8 -0
- package/src/index.ts +2 -1
- package/src/{boostrap.ts → initializeFirefly.ts} +38 -18
- package/src/useAppRouterStore.ts +8 -0
- package/src/useCanFetchProtectedData.ts +28 -12
- package/dist/boostrap.d.ts +0 -14
- package/dist/boostrap.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack://@squide/firefly/./src/index.ts"],"sourcesContent":["export * from \"@squide/core\";\nexport * from \"@squide/module-federation\";\nexport * from \"@squide/msw\";\nexport * from \"@squide/react-router\";\n\nexport * from \"./FireflyProvider.tsx\";\nexport * from \"./FireflyRuntime.tsx\";\n\nexport * from \"./AppRouter.tsx\";\nexport * from \"./AppRouterContext.ts\";\nexport * from \"./AppRouterReducer.ts\";\n\nexport * from \"./GlobalDataQueriesError.ts\";\nexport * from \"./useCanFetchProtectedData.ts\";\nexport * from \"./useCanFetchPublicData.ts\";\nexport * from \"./useCanRegisterDeferredRegistrations.ts\";\nexport * from \"./useCanUpdateDeferredRegistrations.ts\";\nexport * from \"./useDeferredRegistrations.ts\";\nexport * from \"./useIsActiveRouteProtected.ts\";\nexport * from \"./useIsBootstrapping.ts\";\nexport * from \"./useNavigationItems.ts\";\nexport * from \"./useProtectedDataHandler.ts\";\nexport * from \"./useProtectedDataQueries.ts\";\nexport * from \"./usePublicDataHandler.ts\";\nexport * from \"./usePublicDataQueries.ts\";\nexport * from \"./useRegisterDeferredRegistrations.ts\";\nexport * from \"./useStrictRegistrationMode.ts\";\nexport * from \"./useUpdateDeferredRegistrations.ts\";\n\nexport * from \"./
|
|
1
|
+
{"version":3,"file":"index.js","sources":["webpack://@squide/firefly/./src/index.ts"],"sourcesContent":["export * from \"@squide/core\";\nexport * from \"@squide/module-federation\";\nexport * from \"@squide/msw\";\nexport * from \"@squide/react-router\";\n\nexport * from \"./FireflyProvider.tsx\";\nexport * from \"./FireflyRuntime.tsx\";\n\nexport * from \"./AppRouter.tsx\";\nexport * from \"./AppRouterContext.ts\";\nexport * from \"./AppRouterReducer.ts\";\n\nexport * from \"./AppRouterStore.ts\";\nexport * from \"./GlobalDataQueriesError.ts\";\nexport * from \"./useCanFetchProtectedData.ts\";\nexport * from \"./useCanFetchPublicData.ts\";\nexport * from \"./useCanRegisterDeferredRegistrations.ts\";\nexport * from \"./useCanUpdateDeferredRegistrations.ts\";\nexport * from \"./useDeferredRegistrations.ts\";\nexport * from \"./useIsActiveRouteProtected.ts\";\nexport * from \"./useIsBootstrapping.ts\";\nexport * from \"./useNavigationItems.ts\";\nexport * from \"./useProtectedDataHandler.ts\";\nexport * from \"./useProtectedDataQueries.ts\";\nexport * from \"./usePublicDataHandler.ts\";\nexport * from \"./usePublicDataQueries.ts\";\nexport * from \"./useRegisterDeferredRegistrations.ts\";\nexport * from \"./useStrictRegistrationMode.ts\";\nexport * from \"./useUpdateDeferredRegistrations.ts\";\n\nexport * from \"./initializeFirefly.ts\";\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA6B;AACa;AACd;AACS;AAEC;AACD;AAEL;AACM;AACA;AAEF;AACQ;AACE;AACH;AACc;AACF;AACT;AACC;AACP;AACA;AACK;AACA;AACH;AACA;AACY;AACP;AACK;AAEb"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
|
|
2
|
+
import { type RemoteDefinition } from "@squide/module-federation";
|
|
3
|
+
import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
|
|
4
|
+
export declare const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
|
|
5
|
+
export type OnInitializationErrorFunction = (error: unknown) => void;
|
|
6
|
+
export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
|
|
7
|
+
export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {
|
|
8
|
+
localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
|
|
9
|
+
remotes?: RemoteDefinition[];
|
|
10
|
+
startMsw?: StartMswFunction<FireflyRuntime>;
|
|
11
|
+
onError?: OnInitializationErrorFunction;
|
|
12
|
+
}
|
|
13
|
+
export declare function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options?: InitializeFireflyOptions<TRuntime, TContext, TData>): void;
|
|
14
|
+
export declare function initializeFirefly<TContext = unknown, TData = unknown>(options?: InitializeFireflyOptions<FireflyRuntime, TContext, TData>): FireflyRuntime;
|
|
15
|
+
export declare function __resetHasExecuteGuard(): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE__squide_module_federation_054d2ec6__ from "@squide/module-federation";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__ from "@squide/msw";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__FireflyRuntime_js_318ddfd4__ from "./FireflyRuntime.js";
|
|
4
5
|
|
|
5
6
|
;// CONCATENATED MODULE: external "@squide/core"
|
|
6
7
|
|
|
@@ -8,7 +9,10 @@ import * as __WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__ from "@squide/msw";
|
|
|
8
9
|
|
|
9
10
|
;// CONCATENATED MODULE: external "@squide/msw"
|
|
10
11
|
|
|
11
|
-
;// CONCATENATED MODULE: ./
|
|
12
|
+
;// CONCATENATED MODULE: external "./FireflyRuntime.js"
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: ./src/initializeFirefly.ts?__rslib_entry__
|
|
15
|
+
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
|
|
@@ -22,13 +26,8 @@ function propagateRegistrationErrors(results, onError) {
|
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
|
-
let hasExecuted = false;
|
|
26
29
|
function bootstrap(runtime, options = {}) {
|
|
27
|
-
const { localModules = [], remotes = [],
|
|
28
|
-
if (hasExecuted) {
|
|
29
|
-
throw new Error("[squide] A squide application can only be bootstrapped once. Did you call the \"bootstrap\" function twice?");
|
|
30
|
-
}
|
|
31
|
-
hasExecuted = true;
|
|
30
|
+
const { localModules = [], remotes = [], startMsw, onError, context } = options;
|
|
32
31
|
runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
|
|
33
32
|
Promise.allSettled([
|
|
34
33
|
(0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.registerLocalModules)(localModules, runtime, {
|
|
@@ -54,10 +53,26 @@ function bootstrap(runtime, options = {}) {
|
|
|
54
53
|
}
|
|
55
54
|
});
|
|
56
55
|
}
|
|
56
|
+
let hasExecuted = false;
|
|
57
|
+
function initializeFirefly(options = {}) {
|
|
58
|
+
const { mode, useMsw, loggers, plugins } = options;
|
|
59
|
+
if (hasExecuted) {
|
|
60
|
+
throw new Error("[squide] A squide application can only be initialized once. Did you call the \"initializeSquide\" function twice?");
|
|
61
|
+
}
|
|
62
|
+
hasExecuted = true;
|
|
63
|
+
const runtime = new __WEBPACK_EXTERNAL_MODULE__FireflyRuntime_js_318ddfd4__.FireflyRuntime({
|
|
64
|
+
mode,
|
|
65
|
+
useMsw,
|
|
66
|
+
loggers,
|
|
67
|
+
plugins
|
|
68
|
+
});
|
|
69
|
+
bootstrap(runtime, options);
|
|
70
|
+
return runtime;
|
|
71
|
+
}
|
|
57
72
|
function __resetHasExecuteGuard() {
|
|
58
73
|
hasExecuted = false;
|
|
59
74
|
}
|
|
60
75
|
|
|
61
|
-
export { ApplicationBootstrappingStartedEvent, __resetHasExecuteGuard, bootstrap };
|
|
76
|
+
export { ApplicationBootstrappingStartedEvent, __resetHasExecuteGuard, bootstrap, initializeFirefly };
|
|
62
77
|
|
|
63
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=initializeFirefly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeFirefly.js","sources":["webpack://@squide/firefly/./src/initializeFirefly.ts"],"sourcesContent":["import { isFunction, registerLocalModules, type ModuleRegisterFunction, type RegisterModulesOptions } from \"@squide/core\";\nimport { registerRemoteModules, type RemoteDefinition } from \"@squide/module-federation\";\nimport { setMswAsReady } from \"@squide/msw\";\nimport { FireflyRuntime, type FireflyRuntimeOptions } from \"./FireflyRuntime.tsx\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type OnInitializationErrorFunction = (error: unknown) => void;\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n remotes?: RemoteDefinition[];\n startMsw?: StartMswFunction<FireflyRuntime>;\n onError?: OnInitializationErrorFunction;\n}\n\nfunction propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnInitializationErrorFunction) {\n if (results) {\n if (results.status === \"fulfilled\") {\n results.value.forEach(x => {\n onError(x);\n });\n }\n }\n}\n\nexport function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: InitializeFireflyOptions<TRuntime, TContext, TData> = {}) {\n const {\n localModules = [],\n remotes = [],\n startMsw,\n onError,\n context\n } = options;\n\n runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);\n\n Promise.allSettled([\n registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context }),\n registerRemoteModules(remotes, runtime, { context })\n ]).then(results => {\n if (runtime.isMswEnabled) {\n if (!isFunction(startMsw)) {\n throw new Error(\"[squide] When MSW is enabled, the \\\"startMsw\\\" function must be provided.\");\n }\n\n startMsw(runtime)\n .then(() => {\n setMswAsReady();\n })\n .catch((error: unknown) => {\n runtime.logger.debug(\"[squide] An error occured while starting MSW.\", error);\n });\n }\n\n if (onError) {\n propagateRegistrationErrors(results[0], onError);\n propagateRegistrationErrors(results[1], onError);\n }\n });\n}\n\nlet hasExecuted = false;\n\nexport function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {\n const {\n mode,\n useMsw,\n loggers,\n plugins\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be initialized once. Did you call the \\\"initializeSquide\\\" function twice?\");\n }\n\n hasExecuted = true;\n\n const runtime = new FireflyRuntime({\n mode,\n useMsw,\n loggers,\n plugins\n });\n\n bootstrap(runtime, options);\n\n return runtime;\n}\n\nexport function __resetHasExecuteGuard() {\n hasExecuted = false;\n}\n"],"names":["isFunction","registerLocalModules","registerRemoteModules","setMswAsReady","FireflyRuntime","ApplicationBootstrappingStartedEvent","propagateRegistrationErrors","results","onError","x","bootstrap","runtime","options","localModules","remotes","startMsw","context","Promise","Error","error","hasExecuted","initializeFirefly","mode","useMsw","loggers","plugins","__resetHasExecuteGuard"],"mappings":";;;;;;;;;;;;;;AAA0H;AACjC;AAC7C;AACsC;AAE3E,MAAMK,uCAAuC,mCAAmC;AAavF,SAASC,4BAA4BC,OAAwC,EAAEC,OAAsC;IACjH,IAAID,SAAS;QACT,IAAIA,QAAQ,MAAM,KAAK,aAAa;YAChCA,QAAQ,KAAK,CAAC,OAAO,CAACE,CAAAA;gBAClBD,QAAQC;YACZ;QACJ;IACJ;AACJ;AAEO,SAASC,UAAiGC,OAAiB,EAAEC,UAA+D,CAAC,CAAC;IACjM,MAAM,EACFC,eAAe,EAAE,EACjBC,UAAU,EAAE,EACZC,QAAQ,EACRP,OAAO,EACPQ,OAAO,EACV,GAAGJ;IAEJD,QAAQ,QAAQ,CAAC,QAAQ,CAACN;IAE1BY,QAAQ,UAAU,CAAC;QACfhB,0EAAoBA,CAA4BY,cAAcF,SAAS;YAAEK;QAAQ;QACjFd,wFAAqBA,CAACY,SAASH,SAAS;YAAEK;QAAQ;KACrD,EAAE,IAAI,CAACT,CAAAA;QACJ,IAAII,QAAQ,YAAY,EAAE;YACtB,IAAI,CAACX,gEAAUA,CAACe,WAAW;gBACvB,MAAM,IAAIG,MAAM;YACpB;YAEAH,SAASJ,SACJ,IAAI,CAAC;gBACFR,kEAAaA;YACjB,GACC,KAAK,CAAC,CAACgB;gBACJR,QAAQ,MAAM,CAAC,KAAK,CAAC,iDAAiDQ;YAC1E;QACR;QAEA,IAAIX,SAAS;YACTF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;YACxCF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;QAC5C;IACJ;AACJ;AAEA,IAAIY,cAAc;AAEX,SAASC,kBAAuDT,UAAqE,CAAC,CAAC;IAC1I,MAAM,EACFU,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,OAAO,EACV,GAAGb;IAEJ,IAAIQ,aAAa;QACb,MAAM,IAAIF,MAAM;IACpB;IAEAE,cAAc;IAEd,MAAMT,UAAU,IAAIP,sEAAcA,CAAC;QAC/BkB;QACAC;QACAC;QACAC;IACJ;IAEAf,UAAUC,SAASC;IAEnB,OAAOD;AACX;AAEO,SAASe;IACZN,cAAc;AAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useAppRouterStore(): import("./AppRouterStore.ts").AppRouterStore;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "@squide/core"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/useAppRouterStore.ts?__rslib_entry__
|
|
6
|
+
|
|
7
|
+
function useAppRouterStore() {
|
|
8
|
+
const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
|
|
9
|
+
return runtime.appRouterStore;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useAppRouterStore };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useAppRouterStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAppRouterStore.js","sources":["webpack://@squide/firefly/./src/useAppRouterStore.ts"],"sourcesContent":["import { useRuntime } from \"@squide/core\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport function useAppRouterStore() {\n const runtime = useRuntime() as FireflyRuntime;\n\n return runtime.appRouterStore;\n}\n"],"names":["useRuntime","useAppRouterStore","runtime"],"mappings":";;;;;AAA0C;AAGnC,SAASC;IACZ,MAAMC,UAAUF,gEAAUA;IAE1B,OAAOE,QAAQ,cAAc;AACjC"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import type { ActiveRouteVisiblity } from "./AppRouterReducer.ts";
|
|
2
|
+
export declare function canFetchProtectedData(waitForMsw: boolean, areModulesRegistered: boolean, areModulesReady: boolean, activeRouteVisibility: ActiveRouteVisiblity, isMswReady: boolean): boolean;
|
|
1
3
|
export declare function useCanFetchProtectedData(): boolean;
|
|
@@ -4,14 +4,19 @@ import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./Ap
|
|
|
4
4
|
|
|
5
5
|
;// CONCATENATED MODULE: ./src/useCanFetchProtectedData.ts?__rslib_entry__
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// This function is exported for external integration, like the integration
|
|
8
|
+
// with the Platform Widgets. Do not remove.
|
|
9
|
+
function canFetchProtectedData(waitForMsw, areModulesRegistered, areModulesReady, activeRouteVisibility, isMswReady) {
|
|
10
|
+
return(// Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
|
|
11
11
|
// depends on the protected data.
|
|
12
12
|
(areModulesRegistered || areModulesReady) && activeRouteVisibility === "protected" && (!waitForMsw || isMswReady));
|
|
13
13
|
}
|
|
14
|
+
function useCanFetchProtectedData() {
|
|
15
|
+
const { waitForMsw, areModulesRegistered, areModulesReady, isMswReady, isProtectedDataReady, activeRouteVisibility } = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
|
|
16
|
+
// Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
|
|
17
|
+
return isProtectedDataReady || canFetchProtectedData(waitForMsw, areModulesRegistered, areModulesReady, activeRouteVisibility, isMswReady);
|
|
18
|
+
}
|
|
14
19
|
|
|
15
|
-
export { useCanFetchProtectedData };
|
|
20
|
+
export { canFetchProtectedData, useCanFetchProtectedData };
|
|
16
21
|
|
|
17
22
|
//# sourceMappingURL=useCanFetchProtectedData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCanFetchProtectedData.js","sources":["webpack://@squide/firefly/./src/useCanFetchProtectedData.ts"],"sourcesContent":["import { useAppRouterState } from \"./AppRouterContext.ts\";\
|
|
1
|
+
{"version":3,"file":"useCanFetchProtectedData.js","sources":["webpack://@squide/firefly/./src/useCanFetchProtectedData.ts"],"sourcesContent":["import { useAppRouterState } from \"./AppRouterContext.ts\";\nimport type { ActiveRouteVisiblity } from \"./AppRouterReducer.ts\";\n\n// This function is exported for external integration, like the integration\n// with the Platform Widgets. Do not remove.\nexport function canFetchProtectedData(\n waitForMsw: boolean,\n areModulesRegistered: boolean,\n areModulesReady: boolean,\n activeRouteVisibility: ActiveRouteVisiblity,\n isMswReady: boolean\n) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReady)\n // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.\n && activeRouteVisibility === \"protected\"\n // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.\n && (!waitForMsw || isMswReady)\n );\n}\n\nexport function useCanFetchProtectedData() {\n const {\n waitForMsw,\n areModulesRegistered,\n areModulesReady,\n isMswReady,\n isProtectedDataReady,\n activeRouteVisibility\n } = useAppRouterState();\n\n // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.\n return isProtectedDataReady || canFetchProtectedData(\n waitForMsw,\n areModulesRegistered,\n areModulesReady,\n activeRouteVisibility,\n isMswReady\n );\n}\n"],"names":["useAppRouterState","canFetchProtectedData","waitForMsw","areModulesRegistered","areModulesReady","activeRouteVisibility","isMswReady","useCanFetchProtectedData","isProtectedDataReady"],"mappings":";;;;;AAA0D;AAG1D,2EAA2E;AAC3E,4CAA4C;AACrC,SAASC,sBACZC,UAAmB,EACnBC,oBAA6B,EAC7BC,eAAwB,EACxBC,qBAA2C,EAC3CC,UAAmB;IAEnB,OACI,oIAAoI;IACpI,iCAAiC;IAChCH,CAAAA,wBAAwBC,eAAc,KAEpCC,0BAA0B,eAEzB,EAACH,cAAcI,UAAS;AAEpC;AAEO,SAASC;IACZ,MAAM,EACFL,UAAU,EACVC,oBAAoB,EACpBC,eAAe,EACfE,UAAU,EACVE,oBAAoB,EACpBH,qBAAqB,EACxB,GAAGL,+EAAiBA;IAErB,2IAA2I;IAC3I,OAAOQ,wBAAwBP,sBAC3BC,YACAC,sBACAC,iBACAC,uBACAC;AAER"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "12.0.1",
|
|
5
5
|
"description": "Helpers to facilitate the creation of an application with the Squide firefly technology stack.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@types/react": "19.0.10",
|
|
39
39
|
"@types/react-dom": "19.0.4",
|
|
40
|
-
"@squide/
|
|
41
|
-
"@squide/
|
|
42
|
-
"@squide/msw": "3.2.
|
|
43
|
-
"@squide/react-router": "7.0.
|
|
40
|
+
"@squide/core": "5.4.5",
|
|
41
|
+
"@squide/module-federation": "6.2.5",
|
|
42
|
+
"@squide/msw": "3.2.5",
|
|
43
|
+
"@squide/react-router": "7.0.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rsbuild/core": "1.2.19",
|
package/src/AppRouter.tsx
CHANGED
|
@@ -48,7 +48,6 @@ function useRenderRouterProvider(state: AppRouterState, renderRouterProvider: Re
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export interface AppRouterProps {
|
|
51
|
-
waitForMsw: boolean;
|
|
52
51
|
waitForPublicData?: boolean;
|
|
53
52
|
waitForProtectedData?: boolean;
|
|
54
53
|
children: RenderRouterProviderFunction;
|
|
@@ -56,13 +55,11 @@ export interface AppRouterProps {
|
|
|
56
55
|
|
|
57
56
|
export function AppRouter(props: AppRouterProps) {
|
|
58
57
|
const {
|
|
59
|
-
waitForMsw,
|
|
60
58
|
waitForPublicData = false,
|
|
61
59
|
waitForProtectedData = false,
|
|
62
60
|
children: renderRouterProvider
|
|
63
61
|
} = props;
|
|
64
|
-
|
|
65
|
-
const [state, dispatch] = useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData);
|
|
62
|
+
const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);
|
|
66
63
|
|
|
67
64
|
const logger = useLogger();
|
|
68
65
|
|
package/src/AppRouterReducer.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger } from "@squide/core";
|
|
1
|
+
import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger, useRuntime } from "@squide/core";
|
|
2
2
|
import { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from "@squide/module-federation";
|
|
3
3
|
import { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from "@squide/msw";
|
|
4
4
|
import { useCallback, useEffect, useMemo, useReducer, type Dispatch } from "react";
|
|
5
|
+
import type { FireflyRuntime } from "./FireflyRuntime.tsx";
|
|
6
|
+
import { useAppRouterStore } from "./useAppRouterStore.ts";
|
|
5
7
|
import { useExecuteOnce } from "./useExecuteOnce.ts";
|
|
6
8
|
import { isBootstrapping } from "./useIsBootstrapping.ts";
|
|
7
9
|
|
|
@@ -41,6 +43,8 @@ export type AppRouterActionType =
|
|
|
41
43
|
export const ModulesRegisteredEvent = "squide-modules-registered";
|
|
42
44
|
export const ModulesReadyEvent = "squide-modules-ready";
|
|
43
45
|
export const MswReadyEvent = "squide-msw-ready";
|
|
46
|
+
export const ActiveRouteIsPublicEvent = "squide-active-route-is-public";
|
|
47
|
+
export const ActiveRouteIsProtectedEvent = "squide-active-route-is-protected";
|
|
44
48
|
export const PublicDataReadyEvent = "squide-public-data-ready";
|
|
45
49
|
export const ProtectedDataReadyEvent = "squide-protected-data-ready";
|
|
46
50
|
export const PublicDataUpdatedEvent = "squide-public-data-updated";
|
|
@@ -283,55 +287,63 @@ function useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {
|
|
|
283
287
|
|
|
284
288
|
function useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {
|
|
285
289
|
const logger = useLogger();
|
|
290
|
+
const appRouterStore = useAppRouterStore();
|
|
286
291
|
const eventBus = useEventBus();
|
|
287
292
|
|
|
288
293
|
return useCallback((action: AppRouterAction) => {
|
|
289
294
|
logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
|
|
295
|
+
|
|
296
|
+
appRouterStore.dispatch(action);
|
|
290
297
|
eventBus.dispatch(`squide-${action.type}`);
|
|
291
298
|
|
|
292
299
|
reducerDispatch(action);
|
|
293
|
-
}, [reducerDispatch, logger, eventBus]);
|
|
300
|
+
}, [reducerDispatch, logger, appRouterStore, eventBus]);
|
|
294
301
|
}
|
|
295
302
|
|
|
296
|
-
export function useAppRouterReducer(
|
|
303
|
+
export function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {
|
|
304
|
+
const runtime = useRuntime() as FireflyRuntime;
|
|
305
|
+
const eventBus = useEventBus();
|
|
306
|
+
const appRouterStore = useAppRouterStore();
|
|
307
|
+
|
|
297
308
|
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
298
309
|
const areModulesInitiallyReady = getAreModulesReady();
|
|
299
310
|
const isMswInitiallyReady = isMswReady();
|
|
300
311
|
|
|
301
|
-
const eventBus = useEventBus();
|
|
302
|
-
|
|
303
312
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
304
313
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
305
314
|
useExecuteOnce(useCallback(() => {
|
|
306
315
|
if (areModulesInitiallyRegistered) {
|
|
316
|
+
appRouterStore.dispatch({ type: "modules-registered" });
|
|
307
317
|
eventBus.dispatch(ModulesRegisteredEvent);
|
|
308
318
|
}
|
|
309
319
|
|
|
310
320
|
return true;
|
|
311
|
-
}, [areModulesInitiallyRegistered, eventBus]), true);
|
|
321
|
+
}, [areModulesInitiallyRegistered, appRouterStore, eventBus]), true);
|
|
312
322
|
|
|
313
323
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
314
324
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
315
325
|
useExecuteOnce(useCallback(() => {
|
|
316
326
|
if (areModulesInitiallyReady) {
|
|
327
|
+
appRouterStore.dispatch({ type: "modules-ready" });
|
|
317
328
|
eventBus.dispatch(ModulesReadyEvent);
|
|
318
329
|
}
|
|
319
330
|
|
|
320
331
|
return true;
|
|
321
|
-
}, [areModulesInitiallyReady, eventBus]), true);
|
|
332
|
+
}, [areModulesInitiallyReady, appRouterStore, eventBus]), true);
|
|
322
333
|
|
|
323
334
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
324
335
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
325
336
|
useExecuteOnce(useCallback(() => {
|
|
326
337
|
if (isMswInitiallyReady) {
|
|
338
|
+
appRouterStore.dispatch({ type: "msw-ready" });
|
|
327
339
|
eventBus.dispatch(MswReadyEvent);
|
|
328
340
|
}
|
|
329
341
|
|
|
330
342
|
return true;
|
|
331
|
-
}, [isMswInitiallyReady, eventBus]), true);
|
|
343
|
+
}, [isMswInitiallyReady, appRouterStore, eventBus]), true);
|
|
332
344
|
|
|
333
345
|
const [state, reactDispatch] = useReducer(reducer, {
|
|
334
|
-
waitForMsw,
|
|
346
|
+
waitForMsw: runtime.isMswEnabled,
|
|
335
347
|
waitForPublicData,
|
|
336
348
|
waitForProtectedData,
|
|
337
349
|
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// This file is a low cost port of the AppRouterReducer to a non-React store. It allows, non-React parts of the library to get
|
|
2
|
+
// access to the state and ease the integration with third-party libraries such as the Platform Widgets.
|
|
3
|
+
// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.
|
|
4
|
+
|
|
5
|
+
import type { RuntimeLogger } from "@squide/core";
|
|
6
|
+
import type { AppRouterAction, AppRouterState } from "./AppRouterReducer.ts";
|
|
7
|
+
|
|
8
|
+
export type AppRouterStoreState = Omit<AppRouterState, "waitForMsw" | "waitForPublicData" | "waitForProtectedData">;
|
|
9
|
+
|
|
10
|
+
export type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;
|
|
11
|
+
|
|
12
|
+
export class AppRouterStore {
|
|
13
|
+
#state: AppRouterStoreState;
|
|
14
|
+
|
|
15
|
+
readonly #listeners = new Set<AppRouterStoreListenerFunction>();
|
|
16
|
+
readonly #logger?: RuntimeLogger;
|
|
17
|
+
|
|
18
|
+
constructor(initialialState: AppRouterStoreState, logger: RuntimeLogger) {
|
|
19
|
+
this.#state = initialialState;
|
|
20
|
+
this.#logger = logger;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
subscribe(listener: AppRouterStoreListenerFunction) {
|
|
24
|
+
this.#listeners.add(listener);
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
this.unsuscribe(listener);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unsuscribe(listener: AppRouterStoreListenerFunction) {
|
|
32
|
+
this.#listeners.delete(listener);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
dispatch(action: AppRouterAction) {
|
|
36
|
+
const newState = this.#reducer({ ...this.#state }, action);
|
|
37
|
+
|
|
38
|
+
this.#logger?.debug("[squide] The AppRouterStore state has been updated to:", newState);
|
|
39
|
+
this.#state = newState;
|
|
40
|
+
|
|
41
|
+
// Creating a copy of the listeners in case some are removed during the looping.
|
|
42
|
+
// To be honest, it might not be necessary, I simply don't know.
|
|
43
|
+
new Set(this.#listeners).forEach(x => {
|
|
44
|
+
x(this, () => {
|
|
45
|
+
this.unsuscribe(x);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#reducer(state: AppRouterStoreState, action: AppRouterAction) {
|
|
51
|
+
let newState = state;
|
|
52
|
+
|
|
53
|
+
switch (action.type) {
|
|
54
|
+
case "modules-registered": {
|
|
55
|
+
newState = {
|
|
56
|
+
...newState,
|
|
57
|
+
areModulesRegistered: true
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "modules-ready": {
|
|
63
|
+
newState = {
|
|
64
|
+
...newState,
|
|
65
|
+
areModulesReady: true,
|
|
66
|
+
// Will be set even if the app is not using deferred registrations.
|
|
67
|
+
deferredRegistrationsUpdatedAt: Date.now()
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case "msw-ready": {
|
|
73
|
+
newState = {
|
|
74
|
+
...newState,
|
|
75
|
+
isMswReady: true
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case "public-data-ready": {
|
|
81
|
+
newState = {
|
|
82
|
+
...newState,
|
|
83
|
+
isPublicDataReady: true,
|
|
84
|
+
publicDataUpdatedAt: Date.now()
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case "protected-data-ready": {
|
|
90
|
+
newState = {
|
|
91
|
+
...newState,
|
|
92
|
+
isProtectedDataReady: true,
|
|
93
|
+
protectedDataUpdatedAt: Date.now()
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "public-data-updated": {
|
|
99
|
+
newState = {
|
|
100
|
+
...newState,
|
|
101
|
+
publicDataUpdatedAt: Date.now()
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case "protected-data-updated": {
|
|
107
|
+
newState = {
|
|
108
|
+
...newState,
|
|
109
|
+
protectedDataUpdatedAt: Date.now()
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "deferred-registrations-updated": {
|
|
115
|
+
newState = {
|
|
116
|
+
...newState,
|
|
117
|
+
deferredRegistrationsUpdatedAt: Date.now()
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "active-route-is-public": {
|
|
123
|
+
newState = {
|
|
124
|
+
...newState,
|
|
125
|
+
activeRouteVisibility: "public"
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "active-route-is-protected": {
|
|
131
|
+
newState = {
|
|
132
|
+
...newState,
|
|
133
|
+
activeRouteVisibility: "protected"
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case "is-unauthorized": {
|
|
139
|
+
newState = {
|
|
140
|
+
...newState,
|
|
141
|
+
isUnauthorized: true
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
default: {
|
|
147
|
+
throw new Error(`[squide] The AppRouterStore state reducer doesn't support action type "${action.type}".`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return newState;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get state() {
|
|
155
|
+
return this.#state;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function createAppRouterStore(logger: RuntimeLogger) {
|
|
160
|
+
const initialState: AppRouterStoreState = {
|
|
161
|
+
areModulesRegistered: false,
|
|
162
|
+
areModulesReady: false,
|
|
163
|
+
isMswReady: false,
|
|
164
|
+
isPublicDataReady: false,
|
|
165
|
+
isProtectedDataReady: false,
|
|
166
|
+
activeRouteVisibility: "unknown",
|
|
167
|
+
isUnauthorized: false
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return new AppRouterStore(initialState, logger);
|
|
171
|
+
}
|
package/src/FireflyRuntime.tsx
CHANGED
|
@@ -3,12 +3,14 @@ import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
|
3
3
|
import { ReactRouterRuntime, type Route } from "@squide/react-router";
|
|
4
4
|
import type { RequestHandler } from "msw";
|
|
5
5
|
import { getAreModulesRegistered } from "./AppRouterReducer.ts";
|
|
6
|
+
import { type AppRouterStore, createAppRouterStore } from "./AppRouterStore.ts";
|
|
6
7
|
|
|
7
8
|
export interface FireflyRuntimeOptions extends RuntimeOptions {
|
|
8
9
|
useMsw?: boolean;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export class FireflyRuntime extends ReactRouterRuntime {
|
|
13
|
+
readonly #appRouterStore: AppRouterStore;
|
|
12
14
|
readonly #useMsw: boolean;
|
|
13
15
|
|
|
14
16
|
constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {
|
|
@@ -30,6 +32,8 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
30
32
|
|
|
31
33
|
this.#useMsw = false;
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
this.#appRouterStore = createAppRouterStore(this._logger);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
registerRequestHandlers(handlers: RequestHandler[]) {
|
|
@@ -65,6 +69,10 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
65
69
|
super.registerRoute(route, options);
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
get appRouterStore() {
|
|
73
|
+
return this.#appRouterStore;
|
|
74
|
+
}
|
|
75
|
+
|
|
68
76
|
get isMswEnabled() {
|
|
69
77
|
return this.#useMsw;
|
|
70
78
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./AppRouter.tsx";
|
|
|
10
10
|
export * from "./AppRouterContext.ts";
|
|
11
11
|
export * from "./AppRouterReducer.ts";
|
|
12
12
|
|
|
13
|
+
export * from "./AppRouterStore.ts";
|
|
13
14
|
export * from "./GlobalDataQueriesError.ts";
|
|
14
15
|
export * from "./useCanFetchProtectedData.ts";
|
|
15
16
|
export * from "./useCanFetchPublicData.ts";
|
|
@@ -27,5 +28,5 @@ export * from "./useRegisterDeferredRegistrations.ts";
|
|
|
27
28
|
export * from "./useStrictRegistrationMode.ts";
|
|
28
29
|
export * from "./useUpdateDeferredRegistrations.ts";
|
|
29
30
|
|
|
30
|
-
export * from "./
|
|
31
|
+
export * from "./initializeFirefly.ts";
|
|
31
32
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { isFunction, registerLocalModules, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
|
|
2
2
|
import { registerRemoteModules, type RemoteDefinition } from "@squide/module-federation";
|
|
3
3
|
import { setMswAsReady } from "@squide/msw";
|
|
4
|
-
import
|
|
4
|
+
import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
|
|
5
5
|
|
|
6
6
|
export const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type OnInitializationErrorFunction = (error: unknown) => void;
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
|
|
11
11
|
|
|
12
|
-
export interface
|
|
12
|
+
export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {
|
|
13
13
|
localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
|
|
14
14
|
remotes?: RemoteDefinition[];
|
|
15
|
-
startMsw?: StartMswFunction<
|
|
16
|
-
onError?:
|
|
15
|
+
startMsw?: StartMswFunction<FireflyRuntime>;
|
|
16
|
+
onError?: OnInitializationErrorFunction;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError:
|
|
19
|
+
function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnInitializationErrorFunction) {
|
|
20
20
|
if (results) {
|
|
21
21
|
if (results.status === "fulfilled") {
|
|
22
22
|
results.value.forEach(x => {
|
|
@@ -26,23 +26,15 @@ function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, o
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: BootstrapAppOptions<TRuntime, TContext, TData> = {}) {
|
|
29
|
+
export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: InitializeFireflyOptions<TRuntime, TContext, TData> = {}) {
|
|
32
30
|
const {
|
|
33
31
|
localModules = [],
|
|
34
32
|
remotes = [],
|
|
35
|
-
context,
|
|
36
33
|
startMsw,
|
|
37
|
-
onError
|
|
34
|
+
onError,
|
|
35
|
+
context
|
|
38
36
|
} = options;
|
|
39
37
|
|
|
40
|
-
if (hasExecuted) {
|
|
41
|
-
throw new Error("[squide] A squide application can only be bootstrapped once. Did you call the \"bootstrap\" function twice?");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
hasExecuted = true;
|
|
45
|
-
|
|
46
38
|
runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
|
|
47
39
|
|
|
48
40
|
Promise.allSettled([
|
|
@@ -70,6 +62,34 @@ export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TCon
|
|
|
70
62
|
});
|
|
71
63
|
}
|
|
72
64
|
|
|
65
|
+
let hasExecuted = false;
|
|
66
|
+
|
|
67
|
+
export function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {
|
|
68
|
+
const {
|
|
69
|
+
mode,
|
|
70
|
+
useMsw,
|
|
71
|
+
loggers,
|
|
72
|
+
plugins
|
|
73
|
+
} = options;
|
|
74
|
+
|
|
75
|
+
if (hasExecuted) {
|
|
76
|
+
throw new Error("[squide] A squide application can only be initialized once. Did you call the \"initializeSquide\" function twice?");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
hasExecuted = true;
|
|
80
|
+
|
|
81
|
+
const runtime = new FireflyRuntime({
|
|
82
|
+
mode,
|
|
83
|
+
useMsw,
|
|
84
|
+
loggers,
|
|
85
|
+
plugins
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
bootstrap(runtime, options);
|
|
89
|
+
|
|
90
|
+
return runtime;
|
|
91
|
+
}
|
|
92
|
+
|
|
73
93
|
export function __resetHasExecuteGuard() {
|
|
74
94
|
hasExecuted = false;
|
|
75
95
|
}
|