@squide/firefly 11.0.0 → 12.0.0

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @squide/firefly
2
2
 
3
+ ## 12.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#249](https://github.com/workleap/wl-squide/pull/249) [`9429e98`](https://github.com/workleap/wl-squide/commit/9429e98382f054ed560297aa8a1e54caba40db4f) Thanks [@patricklafrance](https://github.com/patricklafrance)! - - Replace the `bootstrap` function by a new `initializeFirefly` function that takes care of creating the `FireflyRuntime` instance.
8
+ - The `FireflyRuntime` instance now expose a new `BootstrappingStore` instance.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [[`9429e98`](https://github.com/workleap/wl-squide/commit/9429e98382f054ed560297aa8a1e54caba40db4f), [`9429e98`](https://github.com/workleap/wl-squide/commit/9429e98382f054ed560297aa8a1e54caba40db4f)]:
13
+ - @squide/module-federation@6.2.5
14
+ - @squide/core@5.4.5
15
+ - @squide/msw@3.2.5
16
+ - @squide/react-router@7.0.3
17
+
3
18
  ## 11.0.0
4
19
 
5
20
  ### Major Changes
@@ -13,7 +13,6 @@ export interface RenderRouterProviderFunctionArgs {
13
13
  export type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;
14
14
  export declare function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState): boolean;
15
15
  export interface AppRouterProps {
16
- waitForMsw: boolean;
17
16
  waitForPublicData?: boolean;
18
17
  waitForProtectedData?: boolean;
19
18
  children: RenderRouterProviderFunction;
package/dist/AppRouter.js CHANGED
@@ -58,8 +58,8 @@ function useRenderRouterProvider(state, renderRouterProvider) {
58
58
  ]);
59
59
  }
60
60
  function AppRouter(props) {
61
- const { waitForMsw, waitForPublicData = false, waitForProtectedData = false, children: renderRouterProvider } = props;
62
- const [state, dispatch] = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterReducer_js_6fa81ecc__.useAppRouterReducer)(waitForMsw, waitForPublicData, waitForProtectedData);
61
+ const { waitForPublicData = false, waitForProtectedData = false, children: renderRouterProvider } = props;
62
+ const [state, dispatch] = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterReducer_js_6fa81ecc__.useAppRouterReducer)(waitForPublicData, waitForProtectedData);
63
63
  const logger = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useLogger)();
64
64
  (0,__WEBPACK_EXTERNAL_MODULE__useStrictRegistrationMode_js_f67d8785__.useStrictRegistrationMode)();
65
65
  (0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
@@ -1 +1 @@
1
- {"version":3,"file":"AppRouter.js","sources":["webpack://@squide/firefly/./src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider]);\n}\n\nexport interface AppRouterProps {\n waitForMsw: boolean;\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForMsw,\n waitForPublicData = false,\n waitForProtectedData = false,\n children: renderRouterProvider\n } = props;\n\n const [state, dispatch] = useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode();\n\n useEffect(() => {\n logger.debug(\"[squide] AppRouter state updated:\", state);\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","routes","canRenderRouter","AppRouter","props","waitForMsw","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD;IACtG,MAAMC,SAASd,uEAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMe,kBAAkBP,mBAAmBI;IAE3C,OAAOV,6CAAOA,CAAC;QACX,IAAIa,iBAAiB;YACjB,OAAOF,qBAAqB;gBACxB,yBAAW,+DAACP,4DAASA;gBACrB,kBAAkBQ;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQD;KAAqB;AACtD;AASO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,UAAU,EACVC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5B,UAAUP,oBAAoB,EACjC,GAAGI;IAEJ,MAAM,CAACL,OAAOS,SAAS,GAAGhB,iFAAmBA,CAACa,YAAYC,mBAAmBC;IAE7E,MAAME,SAASvB,+DAASA;IAExBQ,gGAAyBA;IAEzBN,+CAASA,CAAC;QACNqB,OAAO,KAAK,CAAC,qCAAqCV;IACtD,GAAG;QAACA;QAAOU;KAAO;IAElB,MAAMC,iBAAiBZ,wBAAwBC,OAAOC;IAEtD,qBACI,+DAACV,6FAAmC;QAAC,OAAOkB;kBACxC,6EAACjB,wFAA8B;YAAC,OAAOQ;sBAClCW;;;AAIjB"}
1
+ {"version":3,"file":"AppRouter.js","sources":["webpack://@squide/firefly/./src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider]);\n}\n\nexport interface AppRouterProps {\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForPublicData = false,\n waitForProtectedData = false,\n children: renderRouterProvider\n } = props;\n const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode();\n\n useEffect(() => {\n logger.debug(\"[squide] AppRouter state updated:\", state);\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","routes","canRenderRouter","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD;IACtG,MAAMC,SAASd,uEAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMe,kBAAkBP,mBAAmBI;IAE3C,OAAOV,6CAAOA,CAAC;QACX,IAAIa,iBAAiB;YACjB,OAAOF,qBAAqB;gBACxB,yBAAW,+DAACP,4DAASA;gBACrB,kBAAkBQ;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQD;KAAqB;AACtD;AAQO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5B,UAAUN,oBAAoB,EACjC,GAAGI;IACJ,MAAM,CAACL,OAAOQ,SAAS,GAAGf,iFAAmBA,CAACa,mBAAmBC;IAEjE,MAAME,SAAStB,+DAASA;IAExBQ,gGAAyBA;IAEzBN,+CAASA,CAAC;QACNoB,OAAO,KAAK,CAAC,qCAAqCT;IACtD,GAAG;QAACA;QAAOS;KAAO;IAElB,MAAMC,iBAAiBX,wBAAwBC,OAAOC;IAEtD,qBACI,+DAACV,6FAAmC;QAAC,OAAOiB;kBACxC,6EAAChB,wFAA8B;YAAC,OAAOQ;sBAClCU;;;AAIjB"}
@@ -19,6 +19,8 @@ export type AppRouterActionType = "modules-registered" | "modules-ready" | "msw-
19
19
  export declare const ModulesRegisteredEvent = "squide-modules-registered";
20
20
  export declare const ModulesReadyEvent = "squide-modules-ready";
21
21
  export declare const MswReadyEvent = "squide-msw-ready";
22
+ export declare const ActiveRouteIsPublicEvent = "squide-active-route-is-public";
23
+ export declare const ActiveRouteIsProtectedEvent = "squide-active-route-is-protected";
22
24
  export declare const PublicDataReadyEvent = "squide-public-data-ready";
23
25
  export declare const ProtectedDataReadyEvent = "squide-protected-data-ready";
24
26
  export declare const PublicDataUpdatedEvent = "squide-public-data-updated";
@@ -36,4 +38,4 @@ export declare function useMswStatusDispatcher(isMswReadyValue: boolean, dispatc
36
38
  export declare function useBootstrappingCompletedDispatcher(state: AppRouterState): void;
37
39
  export declare function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch): void;
38
40
  export declare function __clearAppReducerDispatchProxy(): void;
39
- export declare function useAppRouterReducer(waitForMsw: boolean, waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch];
41
+ export declare function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch];
@@ -29,6 +29,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__ from "./
29
29
  const ModulesRegisteredEvent = "squide-modules-registered";
30
30
  const ModulesReadyEvent = "squide-modules-ready";
31
31
  const MswReadyEvent = "squide-msw-ready";
32
+ const ActiveRouteIsPublicEvent = "squide-active-route-is-public";
33
+ const ActiveRouteIsProtectedEvent = "squide-active-route-is-protected";
32
34
  const PublicDataReadyEvent = "squide-public-data-ready";
33
35
  const ProtectedDataReadyEvent = "squide-protected-data-ready";
34
36
  const PublicDataUpdatedEvent = "squide-public-data-updated";
@@ -257,19 +259,19 @@ function useReducerDispatchProxy(reactDispatch) {
257
259
  ]);
258
260
  }
259
261
  function useEnhancedReducerDispatch(reducerDispatch) {
260
- const logger = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useLogger)();
261
- const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useEventBus)();
262
+ const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
262
263
  return (0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)((action)=>{
263
- logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
264
- eventBus.dispatch(`squide-${action.type}`);
264
+ runtime.logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
265
+ runtime.appRouterStore.dispatch(action);
266
+ runtime.eventBus.dispatch(`squide-${action.type}`);
265
267
  reducerDispatch(action);
266
268
  }, [
267
269
  reducerDispatch,
268
- logger,
269
- eventBus
270
+ runtime
270
271
  ]);
271
272
  }
272
- function useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData) {
273
+ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
274
+ const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
273
275
  const areModulesInitiallyRegistered = getAreModulesRegistered();
274
276
  const areModulesInitiallyReady = getAreModulesReady();
275
277
  const isMswInitiallyReady = (0,__WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__.isMswReady)();
@@ -308,7 +310,7 @@ function useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData
308
310
  eventBus
309
311
  ]), true);
310
312
  const [state, reactDispatch] = (0,__WEBPACK_EXTERNAL_MODULE_react__.useReducer)(reducer, {
311
- waitForMsw,
313
+ waitForMsw: runtime.isMswEnabled,
312
314
  waitForPublicData,
313
315
  waitForProtectedData,
314
316
  // When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
@@ -334,6 +336,6 @@ function useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData
334
336
  ];
335
337
  }
336
338
 
337
- export { ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useBootstrappingCompletedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
339
+ export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useBootstrappingCompletedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
338
340
 
339
341
  //# sourceMappingURL=AppRouterReducer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppRouterReducer.js","sources":["webpack://@squide/firefly/./src/AppRouterReducer.ts"],"sourcesContent":["import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger } from \"@squide/core\";\nimport { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from \"@squide/module-federation\";\nimport { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from \"@squide/msw\";\nimport { useCallback, useEffect, useMemo, useReducer, type Dispatch } from \"react\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\nimport { isBootstrapping } from \"./useIsBootstrapping.ts\";\n\nexport type ActiveRouteVisiblity = \"unknown\" | \"public\" | \"protected\";\n\nexport interface AppRouterState {\n waitForMsw: boolean;\n waitForPublicData: boolean;\n waitForProtectedData: boolean;\n areModulesRegistered: boolean;\n areModulesReady: boolean;\n isMswReady: boolean;\n isPublicDataReady: boolean;\n isProtectedDataReady: boolean;\n publicDataUpdatedAt?: number;\n protectedDataUpdatedAt?: number;\n deferredRegistrationsUpdatedAt?: number;\n activeRouteVisibility: ActiveRouteVisiblity;\n isUnauthorized: boolean;\n}\n\nexport type AppRouterActionType =\n| \"modules-registered\"\n| \"modules-ready\"\n| \"msw-ready\"\n| \"public-data-ready\"\n| \"protected-data-ready\"\n| \"public-data-updated\"\n| \"protected-data-updated\"\n| \"deferred-registrations-updated\"\n| \"active-route-is-public\"\n| \"active-route-is-protected\"\n| \"is-unauthorized\";\n\n// The followings event const are a concatenation of \"squide-\" with AppRouterActionType.\n// They are dispatched by the useEnhancedReducerDispatch hook.\nexport const ModulesRegisteredEvent = \"squide-modules-registered\";\nexport const ModulesReadyEvent = \"squide-modules-ready\";\nexport const MswReadyEvent = \"squide-msw-ready\";\nexport const PublicDataReadyEvent = \"squide-public-data-ready\";\nexport const ProtectedDataReadyEvent = \"squide-protected-data-ready\";\nexport const PublicDataUpdatedEvent = \"squide-public-data-updated\";\nexport const ProtectedDataUpdatedEvent = \"squide-protected-data-updated\";\nexport const DeferredRegistrationsUpdatedEvent = \"squide-deferred-registrations-updated\";\nexport const ApplicationBoostrappedEvent = \"squide-app-boostrapped\";\n\nexport interface AppRouterAction {\n type: AppRouterActionType;\n}\n\nexport type AppRouterDispatch = Dispatch<AppRouterAction>;\n\nfunction reducer(state: AppRouterState, action: AppRouterAction) {\n let newState = state;\n\n switch (action.type) {\n case \"modules-registered\": {\n newState = {\n ...newState,\n areModulesRegistered: true\n };\n\n break;\n }\n case \"modules-ready\": {\n newState = {\n ...newState,\n areModulesReady: true,\n // Will be set even if the app is not using deferred registrations.\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"msw-ready\": {\n newState = {\n ...newState,\n isMswReady: true\n };\n\n break;\n }\n case \"public-data-ready\": {\n newState = {\n ...newState,\n isPublicDataReady: true,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-ready\": {\n newState = {\n ...newState,\n isProtectedDataReady: true,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"public-data-updated\": {\n newState = {\n ...newState,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-updated\": {\n newState = {\n ...newState,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"deferred-registrations-updated\": {\n newState = {\n ...newState,\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"active-route-is-public\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"public\"\n };\n\n break;\n }\n case \"active-route-is-protected\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"protected\"\n };\n\n break;\n }\n case \"is-unauthorized\": {\n newState = {\n ...newState,\n isUnauthorized: true\n };\n\n break;\n }\n default: {\n throw new Error(`[squide] The AppRouter component state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n}\n\nexport function getAreModulesRegistered() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesRegistered(localModuleStatus, remoteModuleStatus);\n}\n\nexport function getAreModulesReady() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesReady(localModuleStatus, remoteModuleStatus);\n}\n\nexport function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useExecuteOnce(useCallback(() => {\n if (getAreModulesRegistered()) {\n dispatch({ type: \"modules-registered\" });\n\n logger.debug(\"[squide] %cModules are registered%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n const dispatchModulesReady = useExecuteOnce(useCallback(() => {\n if (getAreModulesReady()) {\n dispatch({ type: \"modules-ready\" });\n\n logger.debug(\"[squide] %cModules are ready%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n }\n\n return () => {\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useExecuteOnce(useCallback(() => {\n if (isMswReady()) {\n dispatch({ type: \"msw-ready\" });\n\n logger.debug(\"[squide] %cMSW is ready%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n useEffect(() => {\n if (!isMswReadyValue) {\n addMswStateChangedListener(dispatchMswReady);\n }\n\n return () => {\n removeMswStateChangedListener(dispatchMswReady);\n };\n }, [isMswReadyValue, dispatchMswReady]);\n}\n\nexport function useBootstrappingCompletedDispatcher(state: AppRouterState) {\n const eventBus = useEventBus();\n\n const areModulesRegisteredValue = state.areModulesRegistered;\n const isBoostrapping = isBootstrapping(state);\n\n useExecuteOnce(useCallback(() => {\n if (areModulesRegisteredValue && !isBoostrapping) {\n eventBus.dispatch(ApplicationBoostrappedEvent);\n\n return true;\n }\n\n return false;\n }, [areModulesRegisteredValue, isBoostrapping, eventBus]), true);\n}\n\nlet dispatchProxyFactory: ((reactDispatch: AppRouterDispatch) => AppRouterDispatch) | undefined;\n\n// This function should only be used by tests.\nexport function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch) {\n dispatchProxyFactory = factory;\n}\n\n// This function should only be used by tests.\nexport function __clearAppReducerDispatchProxy() {\n dispatchProxyFactory = undefined;\n}\n\nfunction useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {\n return useMemo(() => {\n return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;\n }, [reactDispatch]);\n}\n\nfunction useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {\n const logger = useLogger();\n const eventBus = useEventBus();\n\n return useCallback((action: AppRouterAction) => {\n logger.debug(\"[squide] The following action has been dispatched to the AppRouter reducer:\", action);\n eventBus.dispatch(`squide-${action.type}`);\n\n reducerDispatch(action);\n }, [reducerDispatch, logger, eventBus]);\n}\n\nexport function useAppRouterReducer(waitForMsw: boolean, waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {\n const areModulesInitiallyRegistered = getAreModulesRegistered();\n const areModulesInitiallyReady = getAreModulesReady();\n const isMswInitiallyReady = isMswReady();\n\n const eventBus = useEventBus();\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyRegistered) {\n eventBus.dispatch(ModulesRegisteredEvent);\n }\n\n return true;\n }, [areModulesInitiallyRegistered, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyReady) {\n eventBus.dispatch(ModulesReadyEvent);\n }\n\n return true;\n }, [areModulesInitiallyReady, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (isMswInitiallyReady) {\n eventBus.dispatch(MswReadyEvent);\n }\n\n return true;\n }, [isMswInitiallyReady, eventBus]), true);\n\n const [state, reactDispatch] = useReducer(reducer, {\n waitForMsw,\n waitForPublicData,\n waitForProtectedData,\n // When the modules registration functions are awaited, the event listeners are registered after the modules are registered.\n areModulesRegistered: areModulesInitiallyRegistered,\n areModulesReady: areModulesInitiallyReady,\n isMswReady: isMswInitiallyReady,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n });\n\n const {\n areModulesRegistered: areModulesRegisteredValue,\n areModulesReady: areModulesReadyValue,\n isMswReady: isMswReadyValue\n } = state;\n\n // The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier\n // than mocking the import from React.\n const dispatchProxy = useReducerDispatchProxy(reactDispatch);\n const dispatch = useEnhancedReducerDispatch(dispatchProxy);\n\n useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(isMswReadyValue, dispatch);\n useBootstrappingCompletedDispatcher(state);\n\n return [state, dispatch];\n}\n"],"names":["addLocalModuleRegistrationStatusChangedListener","getLocalModuleRegistrationStatus","removeLocalModuleRegistrationStatusChangedListener","useEventBus","useLogger","addRemoteModuleRegistrationStatusChangedListener","areModulesReady","areModulesRegistered","getRemoteModuleRegistrationStatus","removeRemoteModuleRegistrationStatusChangedListener","addMswStateChangedListener","isMswReady","removeMswStateChangedListener","useCallback","useEffect","useMemo","useReducer","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","getAreModulesRegistered","localModuleStatus","remoteModuleStatus","getAreModulesReady","useModuleRegistrationStatusDispatcher","areModulesRegisteredValue","areModulesReadyValue","dispatch","logger","dispatchModulesRegistered","dispatchModulesReady","useMswStatusDispatcher","isMswReadyValue","dispatchMswReady","useBootstrappingCompletedDispatcher","eventBus","isBoostrapping","dispatchProxyFactory","__setAppReducerDispatchProxyFactory","factory","__clearAppReducerDispatchProxy","undefined","useReducerDispatchProxy","reactDispatch","useEnhancedReducerDispatch","reducerDispatch","useAppRouterReducer","waitForMsw","waitForPublicData","waitForProtectedData","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;;;;AAA6L;AAC+B;AACxH;AACjB;AAC9B;AACK;AAiC1D,wFAAwF;AACxF,8DAA8D;AACvD,MAAMmB,yBAAyB,4BAA4B;AAC3D,MAAMC,oBAAoB,uBAAuB;AACjD,MAAMC,gBAAgB,mBAAmB;AACzC,MAAMC,uBAAuB,2BAA2B;AACxD,MAAMC,0BAA0B,8BAA8B;AAC9D,MAAMC,yBAAyB,6BAA6B;AAC5D,MAAMC,4BAA4B,gCAAgC;AAClE,MAAMC,oCAAoC,wCAAwC;AAClF,MAAMC,8BAA8B,yBAAyB;AAQpE,SAASC,QAAQC,KAAqB,EAAEC,MAAuB;IAC3D,IAAIC,WAAWF;IAEf,OAAQC,OAAO,IAAI;QACf,KAAK;YAAsB;gBACvBC,WAAW;oBACP,GAAGA,QAAQ;oBACX,sBAAsB;gBAC1B;gBAEA;YACJ;QACA,KAAK;YAAiB;gBAClBA,WAAW;oBACP,GAAGA,QAAQ;oBACX,iBAAiB;oBACjB,mEAAmE;oBACnE,gCAAgCC,KAAK,GAAG;gBAC5C;gBAEA;YACJ;QACA,KAAK;YAAa;gBACdD,WAAW;oBACP,GAAGA,QAAQ;oBACX,YAAY;gBAChB;gBAEA;YACJ;QACA,KAAK;YAAqB;gBACtBA,WAAW;oBACP,GAAGA,QAAQ;oBACX,mBAAmB;oBACnB,qBAAqBC,KAAK,GAAG;gBACjC;gBAEA;YACJ;QACA,KAAK;YAAwB;gBACzBD,WAAW;oBACP,GAAGA,QAAQ;oBACX,sBAAsB;oBACtB,wBAAwBC,KAAK,GAAG;gBACpC;gB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OAAO;IACX,GAAG;QAAC6C;QAA0BhB;KAAS,GAAG;IAE1C,2IAA2I;IAC3I,6HAA6H;IAC7HhC,0EAAcA,CAACJ,iDAAWA,CAAC;QACvB,IAAIqD,qBAAqB;YACrBjB,SAAS,QAAQ,CAAC5B;QACtB;QAEA,OAAO;IACX,GAAG;QAAC6C;QAAqBjB;KAAS,GAAG;IAErC,MAAM,CAACpB,OAAO4B,cAAc,GAAGzC,gDAAUA,CAACY,SAAS;QAC/CiC;QACAC;QACAC;QACA,4HAA4H;QAC5H,sBAAsBC;QACtB,iBAAiBC;QACjB,YAAYC;QACZ,mBAAmB;QACnB,sBAAsB;QACtB,uBAAuB;QACvB,gBAAgB;IACpB;IAEA,MAAM,EACF,sBAAsB3B,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGjB;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAMsC,gBAAgBX,wBAAwBC;IAC9C,MAAMhB,WAAWiB,2BAA2BS;IAE5C7B,sCAAsCC,2BAA2BC,sBAAsBC;IACvFI,uBAAuBC,iBAAiBL;IACxCO,oCAAoCnB;IAEpC,OAAO;QAACA;QAAOY;KAAS;AAC5B"}
1
+ {"version":3,"file":"AppRouterReducer.js","sources":["webpack://@squide/firefly/./src/AppRouterReducer.ts"],"sourcesContent":["import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger, useRuntime } from \"@squide/core\";\nimport { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from \"@squide/module-federation\";\nimport { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from \"@squide/msw\";\nimport { useCallback, useEffect, useMemo, useReducer, type Dispatch } from \"react\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\nimport { isBootstrapping } from \"./useIsBootstrapping.ts\";\n\nexport type ActiveRouteVisiblity = \"unknown\" | \"public\" | \"protected\";\n\nexport interface AppRouterState {\n waitForMsw: boolean;\n waitForPublicData: boolean;\n waitForProtectedData: boolean;\n areModulesRegistered: boolean;\n areModulesReady: boolean;\n isMswReady: boolean;\n isPublicDataReady: boolean;\n isProtectedDataReady: boolean;\n publicDataUpdatedAt?: number;\n protectedDataUpdatedAt?: number;\n deferredRegistrationsUpdatedAt?: number;\n activeRouteVisibility: ActiveRouteVisiblity;\n isUnauthorized: boolean;\n}\n\nexport type AppRouterActionType =\n| \"modules-registered\"\n| \"modules-ready\"\n| \"msw-ready\"\n| \"public-data-ready\"\n| \"protected-data-ready\"\n| \"public-data-updated\"\n| \"protected-data-updated\"\n| \"deferred-registrations-updated\"\n| \"active-route-is-public\"\n| \"active-route-is-protected\"\n| \"is-unauthorized\";\n\n// The followings event const are a concatenation of \"squide-\" with AppRouterActionType.\n// They are dispatched by the useEnhancedReducerDispatch hook.\nexport const ModulesRegisteredEvent = \"squide-modules-registered\";\nexport const ModulesReadyEvent = \"squide-modules-ready\";\nexport const MswReadyEvent = \"squide-msw-ready\";\nexport const ActiveRouteIsPublicEvent = \"squide-active-route-is-public\";\nexport const ActiveRouteIsProtectedEvent = \"squide-active-route-is-protected\";\nexport const PublicDataReadyEvent = \"squide-public-data-ready\";\nexport const ProtectedDataReadyEvent = \"squide-protected-data-ready\";\nexport const PublicDataUpdatedEvent = \"squide-public-data-updated\";\nexport const ProtectedDataUpdatedEvent = \"squide-protected-data-updated\";\nexport const DeferredRegistrationsUpdatedEvent = \"squide-deferred-registrations-updated\";\nexport const ApplicationBoostrappedEvent = \"squide-app-boostrapped\";\n\nexport interface AppRouterAction {\n type: AppRouterActionType;\n}\n\nexport type AppRouterDispatch = Dispatch<AppRouterAction>;\n\nfunction reducer(state: AppRouterState, action: AppRouterAction) {\n let newState = state;\n\n switch (action.type) {\n case \"modules-registered\": {\n newState = {\n ...newState,\n areModulesRegistered: true\n };\n\n break;\n }\n case \"modules-ready\": {\n newState = {\n ...newState,\n areModulesReady: true,\n // Will be set even if the app is not using deferred registrations.\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"msw-ready\": {\n newState = {\n ...newState,\n isMswReady: true\n };\n\n break;\n }\n case \"public-data-ready\": {\n newState = {\n ...newState,\n isPublicDataReady: true,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-ready\": {\n newState = {\n ...newState,\n isProtectedDataReady: true,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"public-data-updated\": {\n newState = {\n ...newState,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-updated\": {\n newState = {\n ...newState,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"deferred-registrations-updated\": {\n newState = {\n ...newState,\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"active-route-is-public\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"public\"\n };\n\n break;\n }\n case \"active-route-is-protected\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"protected\"\n };\n\n break;\n }\n case \"is-unauthorized\": {\n newState = {\n ...newState,\n isUnauthorized: true\n };\n\n break;\n }\n default: {\n throw new Error(`[squide] The AppRouter component state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n}\n\nexport function getAreModulesRegistered() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesRegistered(localModuleStatus, remoteModuleStatus);\n}\n\nexport function getAreModulesReady() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesReady(localModuleStatus, remoteModuleStatus);\n}\n\nexport function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useExecuteOnce(useCallback(() => {\n if (getAreModulesRegistered()) {\n dispatch({ type: \"modules-registered\" });\n\n logger.debug(\"[squide] %cModules are registered%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n const dispatchModulesReady = useExecuteOnce(useCallback(() => {\n if (getAreModulesReady()) {\n dispatch({ type: \"modules-ready\" });\n\n logger.debug(\"[squide] %cModules are ready%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n }\n\n return () => {\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useExecuteOnce(useCallback(() => {\n if (isMswReady()) {\n dispatch({ type: \"msw-ready\" });\n\n logger.debug(\"[squide] %cMSW is ready%c.\", \"color: white; background-color: green;\", \"\");\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n useEffect(() => {\n if (!isMswReadyValue) {\n addMswStateChangedListener(dispatchMswReady);\n }\n\n return () => {\n removeMswStateChangedListener(dispatchMswReady);\n };\n }, [isMswReadyValue, dispatchMswReady]);\n}\n\nexport function useBootstrappingCompletedDispatcher(state: AppRouterState) {\n const eventBus = useEventBus();\n\n const areModulesRegisteredValue = state.areModulesRegistered;\n const isBoostrapping = isBootstrapping(state);\n\n useExecuteOnce(useCallback(() => {\n if (areModulesRegisteredValue && !isBoostrapping) {\n eventBus.dispatch(ApplicationBoostrappedEvent);\n\n return true;\n }\n\n return false;\n }, [areModulesRegisteredValue, isBoostrapping, eventBus]), true);\n}\n\nlet dispatchProxyFactory: ((reactDispatch: AppRouterDispatch) => AppRouterDispatch) | undefined;\n\n// This function should only be used by tests.\nexport function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch) {\n dispatchProxyFactory = factory;\n}\n\n// This function should only be used by tests.\nexport function __clearAppReducerDispatchProxy() {\n dispatchProxyFactory = undefined;\n}\n\nfunction useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {\n return useMemo(() => {\n return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;\n }, [reactDispatch]);\n}\n\nfunction useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {\n const runtime = useRuntime() as FireflyRuntime;\n\n return useCallback((action: AppRouterAction) => {\n runtime.logger.debug(\"[squide] The following action has been dispatched to the AppRouter reducer:\", action);\n\n runtime.appRouterStore.dispatch(action);\n runtime.eventBus.dispatch(`squide-${action.type}`);\n\n reducerDispatch(action);\n }, [reducerDispatch, runtime]);\n}\n\nexport function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {\n const runtime = useRuntime() as FireflyRuntime;\n\n const areModulesInitiallyRegistered = getAreModulesRegistered();\n const areModulesInitiallyReady = getAreModulesReady();\n const isMswInitiallyReady = isMswReady();\n\n const eventBus = useEventBus();\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyRegistered) {\n eventBus.dispatch(ModulesRegisteredEvent);\n }\n\n return true;\n }, [areModulesInitiallyRegistered, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyReady) {\n eventBus.dispatch(ModulesReadyEvent);\n }\n\n return true;\n }, [areModulesInitiallyReady, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (isMswInitiallyReady) {\n eventBus.dispatch(MswReadyEvent);\n }\n\n return true;\n }, [isMswInitiallyReady, eventBus]), true);\n\n const [state, reactDispatch] = useReducer(reducer, {\n waitForMsw: runtime.isMswEnabled,\n waitForPublicData,\n waitForProtectedData,\n // When the modules registration functions are awaited, the event listeners are registered after the modules are registered.\n areModulesRegistered: areModulesInitiallyRegistered,\n areModulesReady: areModulesInitiallyReady,\n isMswReady: isMswInitiallyReady,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n });\n\n const {\n areModulesRegistered: areModulesRegisteredValue,\n areModulesReady: areModulesReadyValue,\n isMswReady: isMswReadyValue\n } = state;\n\n // The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier\n // than mocking the import from React.\n const dispatchProxy = useReducerDispatchProxy(reactDispatch);\n const dispatch = useEnhancedReducerDispatch(dispatchProxy);\n\n useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(isMswReadyValue, dispatch);\n useBootstrappingCompletedDispatcher(state);\n\n return [state, dispatch];\n}\n"],"names":["addLocalModuleRegistrationStatusChangedListener","getLocalModuleRegistrationStatus","removeLocalModuleRegistrationStatusChangedListener","useEventBus","useLogger","useRuntime","addRemoteModuleRegistrationStatusChangedListener","areModulesReady","areModulesRegistered","getRemoteModuleRegistrationStatus","removeRemoteModuleRegistrationStatusChangedListener","addMswStateChangedListener","isMswReady","removeMswStateChangedListener","useCallback","useEffect","useMemo","useReducer","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","ActiveRouteIsPublicEvent","ActiveRouteIsProtectedEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","getAreModulesRegistered","localModuleStatus","remoteModuleStatus","getAreModulesReady","useModuleRegistrationStatusDispatcher","areModulesRegisteredValue","areModulesReadyValue","dispatch","logger","dispatchModulesRegistered","dispatchModulesReady","useMswStatusDispatcher","isMswReadyValue","dispatchMswReady","useBootstrappingCompletedDispatcher","eventBus","isBoostrapping","dispatchProxyFactory","__setAppReducerDispatchProxyFactory","factory","__clearAppReducerDispatchProxy","undefined","useReducerDispatchProxy","reactDispatch","useEnhancedReducerDispatch","reducerDispatch","runtime","useAppRouterReducer","waitForPublicData","waitForProtectedData","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAyM;AACmB;AACxH;AACjB;AAE9B;AACK;AAiC1D,wFAAwF;AACxF,8DAA8D;AACvD,MAAMoB,yBAAyB,4BAA4B;AAC3D,MAAMC,oBAAoB,uBAAuB;AACjD,MAAMC,gBAAgB,mBAAmB;AACzC,MAAMC,2BAA2B,gCAAgC;AACjE,MAAMC,8BAA8B,mCAAmC;AACvE,MAAMC,uBAAuB,2BAA2B;AACxD,MAAMC,0BAA0B,8BAA8B;AAC9D,MAAMC,yBAAyB,6BAA6B;AAC5D,MAAMC,4BAA4B,gCAAgC;AAClE,MAAMC,oCAAoC,wCAAwC;AAClF,MAAMC,8BAA8B,yBAAyB;AAQpE,SAASC,QAAQC,KAA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MAAMsC,gBAAgBX,wBAAwBC;IAC9C,MAAMhB,WAAWiB,2BAA2BS;IAE5C7B,sCAAsCC,2BAA2BC,sBAAsBC;IACvFI,uBAAuBC,iBAAiBL;IACxCO,oCAAoCnB;IAEpC,OAAO;QAACA;QAAOY;KAAS;AAC5B"}
@@ -0,0 +1,13 @@
1
+ import type { RuntimeLogger } from "@squide/core";
2
+ import type { AppRouterAction, AppRouterState } from "./AppRouterReducer.ts";
3
+ export type AppRouterStoreState = Omit<AppRouterState, "waitForMsw" | "waitForPublicData" | "waitForProtectedData">;
4
+ export type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;
5
+ export declare class AppRouterStore {
6
+ #private;
7
+ constructor(initialialState: AppRouterStoreState, logger: RuntimeLogger);
8
+ subscribe(listener: AppRouterStoreListenerFunction): () => void;
9
+ unsuscribe(listener: AppRouterStoreListenerFunction): void;
10
+ dispatch(action: AppRouterAction): void;
11
+ get state(): AppRouterStoreState;
12
+ }
13
+ export declare function createAppRouterStore(logger: RuntimeLogger): AppRouterStore;
@@ -0,0 +1,158 @@
1
+
2
+ ;// CONCATENATED MODULE: ./src/AppRouterStore.ts?__rslib_entry__
3
+ // 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
4
+ // access to the state and ease the integration with third-party libraries such as the Platform Widgets.
5
+ // Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.
6
+ class AppRouterStore {
7
+ #state;
8
+ #listeners = new Set();
9
+ #logger;
10
+ constructor(initialialState, logger){
11
+ this.#state = initialialState;
12
+ this.#logger = logger;
13
+ }
14
+ subscribe(listener) {
15
+ this.#listeners.add(listener);
16
+ return ()=>{
17
+ this.unsuscribe(listener);
18
+ };
19
+ }
20
+ unsuscribe(listener) {
21
+ this.#listeners.delete(listener);
22
+ }
23
+ dispatch(action) {
24
+ const newState = this.#reducer({
25
+ ...this.#state
26
+ }, action);
27
+ this.#logger?.debug("[squide] The AppRouterStore state has been updated to:", newState);
28
+ this.#state = newState;
29
+ // Creating a copy of the listeners in case some are removed during the looping.
30
+ // To be honest, it might not be necessary, I simply don't know.
31
+ new Set(this.#listeners).forEach((x)=>{
32
+ x(this, ()=>{
33
+ this.unsuscribe(x);
34
+ });
35
+ });
36
+ }
37
+ #reducer(state, action) {
38
+ let newState = state;
39
+ switch(action.type){
40
+ case "modules-registered":
41
+ {
42
+ newState = {
43
+ ...newState,
44
+ areModulesRegistered: true
45
+ };
46
+ break;
47
+ }
48
+ case "modules-ready":
49
+ {
50
+ newState = {
51
+ ...newState,
52
+ areModulesReady: true,
53
+ // Will be set even if the app is not using deferred registrations.
54
+ deferredRegistrationsUpdatedAt: Date.now()
55
+ };
56
+ break;
57
+ }
58
+ case "msw-ready":
59
+ {
60
+ newState = {
61
+ ...newState,
62
+ isMswReady: true
63
+ };
64
+ break;
65
+ }
66
+ case "public-data-ready":
67
+ {
68
+ newState = {
69
+ ...newState,
70
+ isPublicDataReady: true,
71
+ publicDataUpdatedAt: Date.now()
72
+ };
73
+ break;
74
+ }
75
+ case "protected-data-ready":
76
+ {
77
+ newState = {
78
+ ...newState,
79
+ isProtectedDataReady: true,
80
+ protectedDataUpdatedAt: Date.now()
81
+ };
82
+ break;
83
+ }
84
+ case "public-data-updated":
85
+ {
86
+ newState = {
87
+ ...newState,
88
+ publicDataUpdatedAt: Date.now()
89
+ };
90
+ break;
91
+ }
92
+ case "protected-data-updated":
93
+ {
94
+ newState = {
95
+ ...newState,
96
+ protectedDataUpdatedAt: Date.now()
97
+ };
98
+ break;
99
+ }
100
+ case "deferred-registrations-updated":
101
+ {
102
+ newState = {
103
+ ...newState,
104
+ deferredRegistrationsUpdatedAt: Date.now()
105
+ };
106
+ break;
107
+ }
108
+ case "active-route-is-public":
109
+ {
110
+ newState = {
111
+ ...newState,
112
+ activeRouteVisibility: "public"
113
+ };
114
+ break;
115
+ }
116
+ case "active-route-is-protected":
117
+ {
118
+ newState = {
119
+ ...newState,
120
+ activeRouteVisibility: "protected"
121
+ };
122
+ break;
123
+ }
124
+ case "is-unauthorized":
125
+ {
126
+ newState = {
127
+ ...newState,
128
+ isUnauthorized: true
129
+ };
130
+ break;
131
+ }
132
+ default:
133
+ {
134
+ throw new Error(`[squide] The AppRouterStore state reducer doesn't support action type "${action.type}".`);
135
+ }
136
+ }
137
+ return newState;
138
+ }
139
+ get state() {
140
+ return this.#state;
141
+ }
142
+ }
143
+ function createAppRouterStore(logger) {
144
+ const initialState = {
145
+ areModulesRegistered: false,
146
+ areModulesReady: false,
147
+ isMswReady: false,
148
+ isPublicDataReady: false,
149
+ isProtectedDataReady: false,
150
+ activeRouteVisibility: "unknown",
151
+ isUnauthorized: false
152
+ };
153
+ return new AppRouterStore(initialState, logger);
154
+ }
155
+
156
+ export { AppRouterStore, createAppRouterStore };
157
+
158
+ //# sourceMappingURL=AppRouterStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppRouterStore.js","sources":["webpack://@squide/firefly/./src/AppRouterStore.ts"],"sourcesContent":["// 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\n// access to the state and ease the integration with third-party libraries such as the Platform Widgets.\n// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.\n\nimport type { RuntimeLogger } from \"@squide/core\";\nimport type { AppRouterAction, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport type AppRouterStoreState = Omit<AppRouterState, \"waitForMsw\" | \"waitForPublicData\" | \"waitForProtectedData\">;\n\nexport type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;\n\nexport class AppRouterStore {\n #state: AppRouterStoreState;\n\n readonly #listeners = new Set<AppRouterStoreListenerFunction>();\n readonly #logger?: RuntimeLogger;\n\n constructor(initialialState: AppRouterStoreState, logger: RuntimeLogger) {\n this.#state = initialialState;\n this.#logger = logger;\n }\n\n subscribe(listener: AppRouterStoreListenerFunction) {\n this.#listeners.add(listener);\n\n return () => {\n this.unsuscribe(listener);\n };\n }\n\n unsuscribe(listener: AppRouterStoreListenerFunction) {\n this.#listeners.delete(listener);\n }\n\n dispatch(action: AppRouterAction) {\n const newState = this.#reducer({ ...this.#state }, action);\n\n this.#logger?.debug(\"[squide] The AppRouterStore state has been updated to:\", newState);\n this.#state = newState;\n\n // Creating a copy of the listeners in case some are removed during the looping.\n // To be honest, it might not be necessary, I simply don't know.\n new Set(this.#listeners).forEach(x => {\n x(this, () => {\n this.unsuscribe(x);\n });\n });\n }\n\n #reducer(state: AppRouterStoreState, action: AppRouterAction) {\n let newState = state;\n\n switch (action.type) {\n case \"modules-registered\": {\n newState = {\n ...newState,\n areModulesRegistered: true\n };\n\n break;\n }\n case \"modules-ready\": {\n newState = {\n ...newState,\n areModulesReady: true,\n // Will be set even if the app is not using deferred registrations.\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"msw-ready\": {\n newState = {\n ...newState,\n isMswReady: true\n };\n\n break;\n }\n case \"public-data-ready\": {\n newState = {\n ...newState,\n isPublicDataReady: true,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-ready\": {\n newState = {\n ...newState,\n isProtectedDataReady: true,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"public-data-updated\": {\n newState = {\n ...newState,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-updated\": {\n newState = {\n ...newState,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"deferred-registrations-updated\": {\n newState = {\n ...newState,\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"active-route-is-public\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"public\"\n };\n\n break;\n }\n case \"active-route-is-protected\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"protected\"\n };\n\n break;\n }\n case \"is-unauthorized\": {\n newState = {\n ...newState,\n isUnauthorized: true\n };\n\n break;\n }\n default: {\n throw new Error(`[squide] The AppRouterStore state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n }\n\n get state() {\n return this.#state;\n }\n}\n\nexport function createAppRouterStore(logger: RuntimeLogger) {\n const initialState: AppRouterStoreState = {\n areModulesRegistered: false,\n areModulesReady: false,\n isMswReady: false,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n };\n\n return new AppRouterStore(initialState, logger);\n}\n"],"names":["AppRouterStore","Set","initialialState","logger","listener","action","newState","x","state","Date","Error","createAppRouterStore","initialState"],"mappings":";;AAAA,8HAA8H;AAC9H,wGAAwG;AACxG,yFAAyF;AASlF,MAAMA;IACT,MAAM,CAAsB;IAEnB,UAAU,GAAG,IAAIC,MAAsC;IACvD,OAAO,CAAiB;IAEjC,YAAYC,eAAoC,EAAEC,MAAqB,CAAE;QACrE,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,UAAUC,QAAwC,EAAE;QAChD,IAAI,CAAC,UAAU,CAAC,GAAG,CAACA;QAEpB,OAAO;YACH,IAAI,CAAC,UAAU,CAACA;QACpB;IACJ;IAEA,WAAWA,QAAwC,EAAE;QACjD,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAC3B;IAEA,SAASC,MAAuB,EAAE;QAC9B,MAAMC,WAAW,IAAI,CAAC,QAAQ,CAAC;YAAE,GAAG,IAAI,CAAC,MAAM;QAAC,GAAGD;QAEnD,IAAI,CAAC,OAAO,EAAE,MAAM,0DAA0DC;QAC9E,IAAI,CAAC,MAAM,GAAGA;QAEd,gFAAgF;QAChF,gEAAgE;QAChE,IAAIL,IAAI,IAAI,CAAC,UAAU,EAAE,OAAO,CAACM,CAAAA;YAC7BA,EAAE,IAAI,EAAE;gBACJ,IAAI,CAAC,UAAU,CAACA;YACpB;QACJ;IACJ;IAEA,QAAQ,CAACC,KAA0B,EAAEH,MAAuB;QACxD,IAAIC,WAAWE;QAEf,OAAQH,OAAO,IAAI;YACf,KAAK;gBAAsB;oBACv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ACX;IAEA,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;AACJ;AAEO,SAASK,qBAAqBR,MAAqB;IACtD,MAAMS,eAAoC;QACtC,sBAAsB;QACtB,iBAAiB;QACjB,YAAY;QACZ,mBAAmB;QACnB,sBAAsB;QACtB,uBAAuB;QACvB,gBAAgB;IACpB;IAEA,OAAO,IAAIZ,eAAeY,cAAcT;AAC5C"}
@@ -1,6 +1,7 @@
1
1
  import type { RegisterRouteOptions, RuntimeOptions } from "@squide/core";
2
2
  import { ReactRouterRuntime, type Route } from "@squide/react-router";
3
3
  import type { RequestHandler } from "msw";
4
+ import { type AppRouterStore } from "./AppRouterStore.ts";
4
5
  export interface FireflyRuntimeOptions extends RuntimeOptions {
5
6
  useMsw?: boolean;
6
7
  }
@@ -10,5 +11,6 @@ export declare class FireflyRuntime extends ReactRouterRuntime {
10
11
  registerRequestHandlers(handlers: RequestHandler[]): void;
11
12
  get requestHandlers(): RequestHandler[];
12
13
  registerRoute(route: Route, options?: RegisterRouteOptions): void;
14
+ get appRouterStore(): AppRouterStore;
13
15
  get isMswEnabled(): boolean;
14
16
  }
@@ -1,6 +1,7 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__ from "@squide/msw";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a4bef__ from "@squide/react-router";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__AppRouterReducer_js_6fa81ecc__ from "./AppRouterReducer.js";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__AppRouterStore_js_e9778a35__ from "./AppRouterStore.js";
4
5
 
5
6
  ;// CONCATENATED MODULE: external "@squide/msw"
6
7
 
@@ -8,11 +9,15 @@ import * as __WEBPACK_EXTERNAL_MODULE__AppRouterReducer_js_6fa81ecc__ from "./Ap
8
9
 
9
10
  ;// CONCATENATED MODULE: external "./AppRouterReducer.js"
10
11
 
12
+ ;// CONCATENATED MODULE: external "./AppRouterStore.js"
13
+
11
14
  ;// CONCATENATED MODULE: ./src/FireflyRuntime.tsx?__rslib_entry__
12
15
 
13
16
 
14
17
 
18
+
15
19
  class FireflyRuntime extends __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a4bef__.ReactRouterRuntime {
20
+ #appRouterStore;
16
21
  #useMsw;
17
22
  constructor({ plugins, useMsw, ...options } = {}){
18
23
  if (useMsw) {
@@ -31,6 +36,7 @@ class FireflyRuntime extends __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a
31
36
  });
32
37
  this.#useMsw = false;
33
38
  }
39
+ this.#appRouterStore = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterStore_js_e9778a35__.createAppRouterStore)(this._logger);
34
40
  }
35
41
  registerRequestHandlers(handlers) {
36
42
  const mswPlugin = this.getPlugin(__WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__.MswPluginName);
@@ -56,6 +62,9 @@ class FireflyRuntime extends __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a
56
62
  }
57
63
  super.registerRoute(route, options);
58
64
  }
65
+ get appRouterStore() {
66
+ return this.#appRouterStore;
67
+ }
59
68
  get isMswEnabled() {
60
69
  return this.#useMsw;
61
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FireflyRuntime.js","sources":["webpack://@squide/firefly/./src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeOptions } from \"@squide/core\";\nimport { MswPlugin, MswPluginName } from \"@squide/msw\";\nimport { ReactRouterRuntime, type Route } from \"@squide/react-router\";\nimport type { RequestHandler } from \"msw\";\nimport { getAreModulesRegistered } from \"./AppRouterReducer.ts\";\n\nexport interface FireflyRuntimeOptions extends RuntimeOptions {\n useMsw?: boolean;\n}\n\nexport class FireflyRuntime extends ReactRouterRuntime {\n readonly #useMsw: boolean;\n\n constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {\n if (useMsw) {\n super({\n plugins: [\n ...(plugins ?? []),\n runtime => new MswPlugin(runtime)\n ],\n ...options\n });\n\n this.#useMsw = true;\n } else {\n super({\n plugins,\n ...options\n });\n\n this.#useMsw = false;\n }\n }\n\n registerRequestHandlers(handlers: RequestHandler[]) {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n mswPlugin.registerRequestHandlers(handlers);\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n return mswPlugin.requestHandlers;\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register a route once the modules are registered. Are you trying to register a route in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n super.registerRoute(route, options);\n }\n\n get isMswEnabled() {\n return this.#useMsw;\n }\n}\n"],"names":["MswPlugin","MswPluginName","ReactRouterRuntime","getAreModulesRegistered","FireflyRuntime","plugins","useMsw","options","runtime","handlers","mswPlugin","Error","route"],"mappings":";;;;;;;;;;;AACuD;AACe;AAEN;AAMzD,MAAMI,uBAAuBF,4EAAkBA;IACzC,OAAO,CAAU;IAE1B,YAAY,EAAEG,OAAO,EAAEC,MAAM,EAAE,GAAGC,SAAgC,GAAG,CAAC,CAAC,CAAE;QACrE,IAAID,QAAQ;YACR,KAAK,CAAC;gBACF,SAAS;uBACDD,WAAW,EAAE;oBACjBG,CAAAA,UAAW,IAAIR,0DAASA,CAACQ;iBAC5B;gBACD,GAAGD,OAAO;YACd;YAEA,IAAI,CAAC,OAAO,GAAG;QACnB,OAAO;YACH,KAAK,CAAC;gBACFF;gBACA,GAAGE,OAAO;YACd;YAEA,IAAI,CAAC,OAAO,GAAG;QACnB;IACJ;IAEA,wBAAwBE,QAA0B,EAAE;QAChD,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACT,8DAAaA;QAE9C,IAAI,CAACS,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,IAAIR,qFAAuBA,IAAI;YAC3B,MAAM,IAAIQ,MAAM;QACpB;QAEAD,UAAU,uBAAuB,CAACD;IACtC;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACT,8DAAaA;QAE9C,IAAI,CAACS,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,UAAU,eAAe;IACpC;IAEA,cAAcE,KAAY,EAAEL,UAAgC,CAAC,CAAC,EAAE;QAC5D,IAAIJ,qFAAuBA,IAAI;YAC3B,MAAM,IAAIQ,MAAM;QACpB;QAEA,KAAK,CAAC,cAAcC,OAAOL;IAC/B;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,OAAO;IACvB;AACJ"}
1
+ {"version":3,"file":"FireflyRuntime.js","sources":["webpack://@squide/firefly/./src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeOptions } from \"@squide/core\";\nimport { MswPlugin, MswPluginName } from \"@squide/msw\";\nimport { ReactRouterRuntime, type Route } from \"@squide/react-router\";\nimport type { RequestHandler } from \"msw\";\nimport { getAreModulesRegistered } from \"./AppRouterReducer.ts\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions extends RuntimeOptions {\n useMsw?: boolean;\n}\n\nexport class FireflyRuntime extends ReactRouterRuntime {\n readonly #appRouterStore: AppRouterStore;\n readonly #useMsw: boolean;\n\n constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {\n if (useMsw) {\n super({\n plugins: [\n ...(plugins ?? []),\n runtime => new MswPlugin(runtime)\n ],\n ...options\n });\n\n this.#useMsw = true;\n } else {\n super({\n plugins,\n ...options\n });\n\n this.#useMsw = false;\n }\n\n this.#appRouterStore = createAppRouterStore(this._logger);\n }\n\n registerRequestHandlers(handlers: RequestHandler[]) {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n mswPlugin.registerRequestHandlers(handlers);\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n return mswPlugin.requestHandlers;\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register a route once the modules are registered. Are you trying to register a route in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n super.registerRoute(route, options);\n }\n\n get appRouterStore() {\n return this.#appRouterStore;\n }\n\n get isMswEnabled() {\n return this.#useMsw;\n }\n}\n"],"names":["MswPlugin","MswPluginName","ReactRouterRuntime","getAreModulesRegistered","createAppRouterStore","FireflyRuntime","plugins","useMsw","options","runtime","hand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B;AACJ"}
package/dist/index.d.ts CHANGED
@@ -23,4 +23,4 @@ export * from "./usePublicDataQueries.ts";
23
23
  export * from "./useRegisterDeferredRegistrations.ts";
24
24
  export * from "./useStrictRegistrationMode.ts";
25
25
  export * from "./useUpdateDeferredRegistrations.ts";
26
- export * from "./boostrap.ts";
26
+ export * from "./initializeFirefly.ts";
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export * from "./usePublicDataQueries.js";
23
23
  export * from "./useRegisterDeferredRegistrations.js";
24
24
  export * from "./useStrictRegistrationMode.js";
25
25
  export * from "./useUpdateDeferredRegistrations.js";
26
- export * from "./boostrap.js";
26
+ export * from "./initializeFirefly.js";
27
27
 
28
28
  ;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
29
29
 
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 \"./boostrap.ts\";\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA6B;AACa;AACd;AACS;AAEC;AACD;AAEL;AACM;AACA;AAEM;AACE;AACH;AACc;AACF;AACT;AACC;AACP;AACA;AACK;AACA;AACH;AACA;AACY;AACP;AACK;AAEtB"}
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 \"./initializeFirefly.ts\";\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA6B;AACa;AACd;AACS;AAEC;AACD;AAEL;AACM;AACA;AAEM;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: ./src/boostrap.ts?__rslib_entry__
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 = [], context, startMsw, onError } = options;
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=boostrap.js.map
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"}
@@ -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 useCanFetchProtectedData() {
8
- const { waitForMsw, areModulesRegistered, areModulesReady, isMswReady, isProtectedDataReady, activeRouteVisibility } = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
9
- return(// Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
10
- isProtectedDataReady || // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
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\";\n\nexport function useCanFetchProtectedData() {\n const {\n waitForMsw,\n areModulesRegistered,\n areModulesReady,\n isMswReady,\n isProtectedDataReady,\n activeRouteVisibility\n } = useAppRouterState();\n\n return (\n // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.\n isProtectedDataReady\n || (\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}\n"],"names":["useAppRouterState","useCanFetchProtectedData","waitForMsw","areModulesRegistered","areModulesReady","isMswReady","isProtectedDataReady","activeRouteVisibility"],"mappings":";;;;;AAA0D;AAEnD,SAASC;IACZ,MAAM,EACFC,UAAU,EACVC,oBAAoB,EACpBC,eAAe,EACfC,UAAU,EACVC,oBAAoB,EACpBC,qBAAqB,EACxB,GAAGP,+EAAiBA;IAErB,OACI,2IAA2I;IAC3IM,wBAEI,oIAAoI;IACpI,iCAAiC;IAChCH,CAAAA,wBAAwBC,eAAc,KAEpCG,0BAA0B,eAEzB,EAACL,cAAcG,UAAS;AAGxC"}
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": "11.0.0",
4
+ "version": "12.0.0",
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/module-federation": "6.2.4",
41
- "@squide/core": "5.4.4",
42
- "@squide/msw": "3.2.4",
43
- "@squide/react-router": "7.0.2"
40
+ "@squide/core": "5.4.5",
41
+ "@squide/module-federation": "6.2.5",
42
+ "@squide/react-router": "7.0.3",
43
+ "@squide/msw": "3.2.5"
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
 
@@ -1,7 +1,8 @@
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";
5
6
  import { useExecuteOnce } from "./useExecuteOnce.ts";
6
7
  import { isBootstrapping } from "./useIsBootstrapping.ts";
7
8
 
@@ -41,6 +42,8 @@ export type AppRouterActionType =
41
42
  export const ModulesRegisteredEvent = "squide-modules-registered";
42
43
  export const ModulesReadyEvent = "squide-modules-ready";
43
44
  export const MswReadyEvent = "squide-msw-ready";
45
+ export const ActiveRouteIsPublicEvent = "squide-active-route-is-public";
46
+ export const ActiveRouteIsProtectedEvent = "squide-active-route-is-protected";
44
47
  export const PublicDataReadyEvent = "squide-public-data-ready";
45
48
  export const ProtectedDataReadyEvent = "squide-protected-data-ready";
46
49
  export const PublicDataUpdatedEvent = "squide-public-data-updated";
@@ -282,18 +285,21 @@ function useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {
282
285
  }
283
286
 
284
287
  function useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {
285
- const logger = useLogger();
286
- const eventBus = useEventBus();
288
+ const runtime = useRuntime() as FireflyRuntime;
287
289
 
288
290
  return useCallback((action: AppRouterAction) => {
289
- logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
290
- eventBus.dispatch(`squide-${action.type}`);
291
+ runtime.logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
292
+
293
+ runtime.appRouterStore.dispatch(action);
294
+ runtime.eventBus.dispatch(`squide-${action.type}`);
291
295
 
292
296
  reducerDispatch(action);
293
- }, [reducerDispatch, logger, eventBus]);
297
+ }, [reducerDispatch, runtime]);
294
298
  }
295
299
 
296
- export function useAppRouterReducer(waitForMsw: boolean, waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {
300
+ export function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {
301
+ const runtime = useRuntime() as FireflyRuntime;
302
+
297
303
  const areModulesInitiallyRegistered = getAreModulesRegistered();
298
304
  const areModulesInitiallyReady = getAreModulesReady();
299
305
  const isMswInitiallyReady = isMswReady();
@@ -331,7 +337,7 @@ export function useAppRouterReducer(waitForMsw: boolean, waitForPublicData: bool
331
337
  }, [isMswInitiallyReady, eventBus]), true);
332
338
 
333
339
  const [state, reactDispatch] = useReducer(reducer, {
334
- waitForMsw,
340
+ waitForMsw: runtime.isMswEnabled,
335
341
  waitForPublicData,
336
342
  waitForProtectedData,
337
343
  // 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
+ }
@@ -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
@@ -27,5 +27,5 @@ export * from "./useRegisterDeferredRegistrations.ts";
27
27
  export * from "./useStrictRegistrationMode.ts";
28
28
  export * from "./useUpdateDeferredRegistrations.ts";
29
29
 
30
- export * from "./boostrap.ts";
30
+ export * from "./initializeFirefly.ts";
31
31
 
@@ -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 type { FireflyRuntime } from "./FireflyRuntime.tsx";
4
+ import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
5
5
 
6
6
  export const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
7
7
 
8
- export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
8
+ export type OnInitializationErrorFunction = (error: unknown) => void;
9
9
 
10
- export type OnBootstrapErrorFunction = (error: unknown) => void;
10
+ export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
11
11
 
12
- export interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {
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<TRuntime>;
16
- onError?: OnBootstrapErrorFunction;
15
+ startMsw?: StartMswFunction<FireflyRuntime>;
16
+ onError?: OnInitializationErrorFunction;
17
17
  }
18
18
 
19
- function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnBootstrapErrorFunction) {
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
- let hasExecuted = false;
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
  }
@@ -1,4 +1,25 @@
1
1
  import { useAppRouterState } from "./AppRouterContext.ts";
2
+ import type { ActiveRouteVisiblity } from "./AppRouterReducer.ts";
3
+
4
+ // This function is exported for external integration, like the integration
5
+ // with the Platform Widgets. Do not remove.
6
+ export function canFetchProtectedData(
7
+ waitForMsw: boolean,
8
+ areModulesRegistered: boolean,
9
+ areModulesReady: boolean,
10
+ activeRouteVisibility: ActiveRouteVisiblity,
11
+ isMswReady: boolean
12
+ ) {
13
+ return (
14
+ // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
15
+ // depends on the protected data.
16
+ (areModulesRegistered || areModulesReady)
17
+ // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
18
+ && activeRouteVisibility === "protected"
19
+ // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
20
+ && (!waitForMsw || isMswReady)
21
+ );
22
+ }
2
23
 
3
24
  export function useCanFetchProtectedData() {
4
25
  const {
@@ -10,17 +31,12 @@ export function useCanFetchProtectedData() {
10
31
  activeRouteVisibility
11
32
  } = useAppRouterState();
12
33
 
13
- return (
14
- // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
15
- isProtectedDataReady
16
- || (
17
- // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
18
- // depends on the protected data.
19
- (areModulesRegistered || areModulesReady)
20
- // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
21
- && activeRouteVisibility === "protected"
22
- // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
23
- && (!waitForMsw || isMswReady)
24
- )
34
+ // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
35
+ return isProtectedDataReady || canFetchProtectedData(
36
+ waitForMsw,
37
+ areModulesRegistered,
38
+ areModulesReady,
39
+ activeRouteVisibility,
40
+ isMswReady
25
41
  );
26
42
  }
@@ -1,14 +0,0 @@
1
- import { type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
- import { type RemoteDefinition } from "@squide/module-federation";
3
- import type { FireflyRuntime } from "./FireflyRuntime.tsx";
4
- export declare const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
5
- export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
6
- export type OnBootstrapErrorFunction = (error: unknown) => void;
7
- export interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {
8
- localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
9
- remotes?: RemoteDefinition[];
10
- startMsw?: StartMswFunction<TRuntime>;
11
- onError?: OnBootstrapErrorFunction;
12
- }
13
- export declare function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options?: BootstrapAppOptions<TRuntime, TContext, TData>): void;
14
- export declare function __resetHasExecuteGuard(): void;
@@ -1 +0,0 @@
1
- {"version":3,"file":"boostrap.js","sources":["webpack://@squide/firefly/./src/boostrap.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 type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport type OnBootstrapErrorFunction = (error: unknown) => void;\n\nexport interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n remotes?: RemoteDefinition[];\n startMsw?: StartMswFunction<TRuntime>;\n onError?: OnBootstrapErrorFunction;\n}\n\nfunction propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnBootstrapErrorFunction) {\n if (results) {\n if (results.status === \"fulfilled\") {\n results.value.forEach(x => {\n onError(x);\n });\n }\n }\n}\n\nlet hasExecuted = false;\n\nexport function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: BootstrapAppOptions<TRuntime, TContext, TData> = {}) {\n const {\n localModules = [],\n remotes = [],\n context,\n startMsw,\n onError\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be bootstrapped once. Did you call the \\\"bootstrap\\\" function twice?\");\n }\n\n hasExecuted = true;\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\nexport function __resetHasExecuteGuard() {\n hasExecuted = false;\n}\n"],"names":["isFunction","registerLocalModules","registerRemoteModules","setMswAsReady","ApplicationBootstrappingStartedEvent","propagateRegistrationErrors","results","onError","x","hasExecuted","bootstrap","runtime","options","localModules","remotes","context","startMsw","Error","Promise","error","__resetHasExecuteGuard"],"mappings":";;;;;;;;;;;AAA0H;AACjC;AAC7C;AAGrC,MAAMI,uCAAuC,mCAAmC;AAavF,SAASC,4BAA4BC,OAAwC,EAAEC,OAAiC;IAC5G,IAAID,SAAS;QACT,IAAIA,QAAQ,MAAM,KAAK,aAAa;YAChCA,QAAQ,KAAK,CAAC,OAAO,CAACE,CAAAA;gBAClBD,QAAQC;YACZ;QACJ;IACJ;AACJ;AAEA,IAAIC,cAAc;AAEX,SAASC,UAAiGC,OAAiB,EAAEC,UAA0D,CAAC,CAAC;IAC5L,MAAM,EACFC,eAAe,EAAE,EACjBC,UAAU,EAAE,EACZC,OAAO,EACPC,QAAQ,EACRT,OAAO,EACV,GAAGK;IAEJ,IAAIH,aAAa;QACb,MAAM,IAAIQ,MAAM;IACpB;IAEAR,cAAc;IAEdE,QAAQ,QAAQ,CAAC,QAAQ,CAACP;IAE1Bc,QAAQ,UAAU,CAAC;QACfjB,0EAAoBA,CAA4BY,cAAcF,SAAS;YAAEI;QAAQ;QACjFb,wFAAqBA,CAACY,SAASH,SAAS;YAAEI;QAAQ;KACrD,EAAE,IAAI,CAACT,CAAAA;QACJ,IAAIK,QAAQ,YAAY,EAAE;YACtB,IAAI,CAACX,gEAAUA,CAACgB,WAAW;gBACvB,MAAM,IAAIC,MAAM;YACpB;YAEAD,SAASL,SACJ,IAAI,CAAC;gBACFR,kEAAaA;YACjB,GACC,KAAK,CAAC,CAACgB;gBACJR,QAAQ,MAAM,CAAC,KAAK,CAAC,iDAAiDQ;YAC1E;QACR;QAEA,IAAIZ,SAAS;YACTF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;YACxCF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;QAC5C;IACJ;AACJ;AAEO,SAASa;IACZX,cAAc;AAClB"}