@squide/firefly 10.0.1 → 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.
Files changed (50) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/AppRouter.d.ts +2 -1
  3. package/dist/AppRouter.js +29 -14
  4. package/dist/AppRouter.js.map +1 -1
  5. package/dist/AppRouterReducer.d.ts +3 -1
  6. package/dist/AppRouterReducer.js +12 -10
  7. package/dist/AppRouterReducer.js.map +1 -1
  8. package/dist/AppRouterStore.d.ts +13 -0
  9. package/dist/AppRouterStore.js +158 -0
  10. package/dist/AppRouterStore.js.map +1 -0
  11. package/dist/FireflyProvider.d.ts +6 -0
  12. package/dist/FireflyProvider.js +21 -0
  13. package/dist/FireflyProvider.js.map +1 -0
  14. package/dist/FireflyRuntime.d.ts +2 -0
  15. package/dist/FireflyRuntime.js +9 -0
  16. package/dist/FireflyRuntime.js.map +1 -1
  17. package/dist/index.d.ts +4 -1
  18. package/dist/index.js +7 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/initializeFirefly.d.ts +15 -0
  21. package/dist/initializeFirefly.js +78 -0
  22. package/dist/initializeFirefly.js.map +1 -0
  23. package/dist/useCanFetchProtectedData.d.ts +2 -0
  24. package/dist/useCanFetchProtectedData.js +10 -5
  25. package/dist/useCanFetchProtectedData.js.map +1 -1
  26. package/dist/useIsBootstrapping.d.ts +1 -1
  27. package/dist/useIsBootstrapping.js +3 -3
  28. package/dist/useIsBootstrapping.js.map +1 -1
  29. package/dist/useProtectedDataHandler.d.ts +1 -0
  30. package/dist/useProtectedDataHandler.js +25 -0
  31. package/dist/useProtectedDataHandler.js.map +1 -0
  32. package/dist/usePublicDataHandler.d.ts +1 -0
  33. package/dist/usePublicDataHandler.js +25 -0
  34. package/dist/usePublicDataHandler.js.map +1 -0
  35. package/package.json +5 -5
  36. package/src/AppRouter.tsx +31 -13
  37. package/src/AppRouterReducer.ts +16 -10
  38. package/src/AppRouterStore.ts +171 -0
  39. package/src/FireflyProvider.tsx +19 -0
  40. package/src/FireflyRuntime.tsx +8 -0
  41. package/src/index.ts +4 -1
  42. package/src/initializeFirefly.ts +95 -0
  43. package/src/useCanFetchProtectedData.ts +28 -12
  44. package/src/useIsBootstrapping.ts +2 -2
  45. package/src/useProtectedDataHandler.ts +12 -0
  46. package/src/usePublicDataHandler.ts +12 -0
  47. package/dist/boostrap.d.ts +0 -15
  48. package/dist/boostrap.js +0 -54
  49. package/dist/boostrap.js.map +0 -1
  50. package/src/boostrap.ts +0 -62
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
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
+
18
+ ## 11.0.0
19
+
20
+ ### Major Changes
21
+
22
+ - [#247](https://github.com/workleap/wl-squide/pull/247) [`ddcb106`](https://github.com/workleap/wl-squide/commit/ddcb106a6b3522e09d1ab92c417725185ffc64e6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - The `bootstrap` function is not async anymore.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`ddcb106`](https://github.com/workleap/wl-squide/commit/ddcb106a6b3522e09d1ab92c417725185ffc64e6), [`ddcb106`](https://github.com/workleap/wl-squide/commit/ddcb106a6b3522e09d1ab92c417725185ffc64e6)]:
27
+ - @squide/core@5.4.4
28
+ - @squide/module-federation@6.2.4
29
+ - @squide/msw@3.2.4
30
+ - @squide/react-router@7.0.2
31
+
3
32
  ## 10.0.1
4
33
 
5
34
  ### Patch Changes
@@ -1,6 +1,7 @@
1
1
  import { type Route } from "@squide/react-router";
2
2
  import { type ReactElement } from "react";
3
3
  import type { RouterProviderProps } from "react-router/dom";
4
+ import { type AppRouterState } from "./AppRouterReducer.ts";
4
5
  export interface AppRouterRenderFunctionArgs {
5
6
  routes: Route[];
6
7
  }
@@ -10,8 +11,8 @@ export interface RenderRouterProviderFunctionArgs {
10
11
  routerProviderProps: Omit<RouterProviderProps, "router">;
11
12
  }
12
13
  export type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;
14
+ export declare function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState): boolean;
13
15
  export interface AppRouterProps {
14
- waitForMsw: boolean;
15
16
  waitForPublicData?: boolean;
16
17
  waitForProtectedData?: boolean;
17
18
  children: RenderRouterProviderFunction;
package/dist/AppRouter.js CHANGED
@@ -32,11 +32,35 @@ import * as __WEBPACK_EXTERNAL_MODULE__useStrictRegistrationMode_js_f67d8785__ f
32
32
 
33
33
 
34
34
 
35
+ function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }) {
36
+ return(// Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably
37
+ // depends on the protected data.
38
+ areModulesRegistered || areModulesReadyValue);
39
+ }
40
+ function useRenderRouterProvider(state, renderRouterProvider) {
41
+ const routes = (0,__WEBPACK_EXTERNAL_MODULE__squide_react_router_299a4bef__.useRoutes)();
42
+ // The value is computed outside of the router provider memo to prevent
43
+ // rendering a new router provider everytime the app router state change.
44
+ const canRenderRouter = useCanRenderRouter(state);
45
+ return (0,__WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
46
+ if (canRenderRouter) {
47
+ return renderRouterProvider({
48
+ rootRoute: /*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__RootRoute_js_5c2fbb69__.RootRoute, {}),
49
+ registeredRoutes: routes,
50
+ routerProviderProps: {}
51
+ });
52
+ }
53
+ return null;
54
+ }, [
55
+ canRenderRouter,
56
+ routes,
57
+ renderRouterProvider
58
+ ]);
59
+ }
35
60
  function AppRouter(props) {
36
- const { waitForMsw, waitForPublicData = false, waitForProtectedData = false, children: renderRouterProvider } = props;
37
- 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);
38
63
  const logger = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useLogger)();
39
- const routes = (0,__WEBPACK_EXTERNAL_MODULE__squide_react_router_299a4bef__.useRoutes)();
40
64
  (0,__WEBPACK_EXTERNAL_MODULE__useStrictRegistrationMode_js_f67d8785__.useStrictRegistrationMode)();
41
65
  (0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
42
66
  logger.debug("[squide] AppRouter state updated:", state);
@@ -44,16 +68,7 @@ function AppRouter(props) {
44
68
  state,
45
69
  logger
46
70
  ]);
47
- const routerProvider = (0,__WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
48
- return renderRouterProvider({
49
- rootRoute: /*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__RootRoute_js_5c2fbb69__.RootRoute, {}),
50
- registeredRoutes: routes,
51
- routerProviderProps: {}
52
- });
53
- }, [
54
- routes,
55
- renderRouterProvider
56
- ]);
71
+ const routerProvider = useRenderRouterProvider(state, renderRouterProvider);
57
72
  return /*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.AppRouterDispatcherContext.Provider, {
58
73
  value: dispatch,
59
74
  children: /*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.AppRouterStateContext.Provider, {
@@ -63,6 +78,6 @@ function AppRouter(props) {
63
78
  });
64
79
  }
65
80
 
66
- export { AppRouter };
81
+ export { AppRouter, useCanRenderRouter };
67
82
 
68
83
  //# sourceMappingURL=AppRouter.js.map
@@ -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 } 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 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 const routes = useRoutes();\n\n useStrictRegistrationMode();\n\n useEffect(() => {\n logger.debug(\"[squide] AppRouter state updated:\", state);\n }, [state, logger]);\n\n const routerProvider = useMemo(() => {\n return renderRouterProvider({\n rootRoute: <RootRoute />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }, [routes, 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","AppRouter","props","waitForMsw","waitForPublicData","waitForProtectedData","renderRouterProvider","state","dispatch","logger","routes","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AAC9B;AAChB;AAC+B;AAqBpE,SAASS,UAAUC,KAAqB;IAC3C,MAAM,EACFC,UAAU,EACVC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5B,UAAUC,oBAAoB,EACjC,GAAGJ;IAEJ,MAAM,CAACK,OAAOC,SAAS,GAAGV,iFAAmBA,CAACK,YAAYC,mBAAmBC;IAE7E,MAAMI,SAASjB,+DAASA;IACxB,MAAMkB,SAASjB,uEAASA;IAExBO,gGAAyBA;IAEzBN,+CAASA,CAAC;QACNe,OAAO,KAAK,CAAC,qCAAqCF;IACtD,GAAG;QAACA;QAAOE;KAAO;IAElB,MAAME,iBAAiBhB,6CAAOA,CAAC;QAC3B,OAAOW,qBAAqB;YACxB,yBAAW,+DAACP,4DAASA;YACrB,kBAAkBW;YAClB,qBAAqB,CAAC;QAC1B;IACJ,GAAG;QAACA;QAAQJ;KAAqB;IAEjC,qBACI,+DAACV,6FAAmC;QAAC,OAAOY;kBACxC,6EAACX,wFAA8B;YAAC,OAAOU;sBAClCI;;;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";
@@ -227,7 +229,7 @@ function useMswStatusDispatcher(isMswReadyValue, dispatch) {
227
229
  function useBootstrappingCompletedDispatcher(state) {
228
230
  const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useEventBus)();
229
231
  const areModulesRegisteredValue = state.areModulesRegistered;
230
- const isBoostrapping = (0,__WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__.isApplicationBootstrapping)(state);
232
+ const isBoostrapping = (0,__WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__.isBootstrapping)(state);
231
233
  (0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
232
234
  if (areModulesRegisteredValue && !isBoostrapping) {
233
235
  eventBus.dispatch(ApplicationBoostrappedEvent);
@@ -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 { isApplicationBootstrapping } 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 = isApplicationBootstrapping(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","isApplicationBootstrapping","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;AACgB;AAiCrE,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;gBAEA;YACJ;QACA,KAAK;YAAuB;gBACxBD,WAAW;oBACP,GAA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,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,KAAqB,EAAEC,MAAuB;IAC3D,IAAIC,WAAWF;IAEf,OAAQC,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BAA2BS;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;oBACvBC,WAAW;wBACP,GAAGA,QAAQ;wBACX,sBAAsB;oBAC1B;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ACtB;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"}
@@ -0,0 +1,6 @@
1
+ import { type Runtime } from "@squide/core";
2
+ import type { PropsWithChildren } from "react";
3
+ export interface FireflyProviderProps extends PropsWithChildren {
4
+ runtime: Runtime;
5
+ }
6
+ export declare function FireflyProvider(props: FireflyProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
3
+
4
+ ;// CONCATENATED MODULE: external "react/jsx-runtime"
5
+
6
+ ;// CONCATENATED MODULE: external "@squide/core"
7
+
8
+ ;// CONCATENATED MODULE: ./src/FireflyProvider.tsx?__rslib_entry__
9
+
10
+
11
+ function FireflyProvider(props) {
12
+ const { runtime, children } = props;
13
+ return /*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.RuntimeContext.Provider, {
14
+ value: runtime,
15
+ children: children
16
+ });
17
+ }
18
+
19
+ export { FireflyProvider };
20
+
21
+ //# sourceMappingURL=FireflyProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FireflyProvider.js","sources":["webpack://@squide/firefly/./src/FireflyProvider.tsx"],"sourcesContent":["import { type Runtime, RuntimeContext } from \"@squide/core\";\nimport type { PropsWithChildren } from \"react\";\n\nexport interface FireflyProviderProps extends PropsWithChildren {\n runtime: Runtime;\n}\n\nexport function FireflyProvider(props: FireflyProviderProps) {\n const {\n runtime,\n children\n } = props;\n\n return (\n <RuntimeContext.Provider value={runtime}>\n {children}\n </RuntimeContext.Provider>\n );\n}\n"],"names":["RuntimeContext","FireflyProvider","props","runtime","children"],"mappings":";;;;;;;;;AAA4D;AAOrD,SAASC,gBAAgBC,KAA2B;IACvD,MAAM,EACFC,OAAO,EACPC,QAAQ,EACX,GAAGF;IAEJ,qBACI,+DAACF,yEAAuB;QAAC,OAAOG;kBAC3BC;;AAGb"}
@@ -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","handlers","mswP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