@squide/firefly 11.0.0 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/AppRouter.d.ts +0 -1
- package/dist/AppRouter.js +2 -2
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterReducer.d.ts +3 -1
- package/dist/AppRouterReducer.js +27 -4
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.d.ts +13 -0
- package/dist/AppRouterStore.js +158 -0
- package/dist/AppRouterStore.js.map +1 -0
- package/dist/FireflyRuntime.d.ts +2 -0
- package/dist/FireflyRuntime.js +9 -0
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.d.ts +15 -0
- package/dist/{boostrap.js → initializeFirefly.js} +24 -9
- package/dist/initializeFirefly.js.map +1 -0
- package/dist/useAppRouterStore.d.ts +1 -0
- package/dist/useAppRouterStore.js +14 -0
- package/dist/useAppRouterStore.js.map +1 -0
- package/dist/useCanFetchProtectedData.d.ts +2 -0
- package/dist/useCanFetchProtectedData.js +10 -5
- package/dist/useCanFetchProtectedData.js.map +1 -1
- package/package.json +5 -5
- package/src/AppRouter.tsx +1 -4
- package/src/AppRouterReducer.ts +21 -9
- package/src/AppRouterStore.ts +171 -0
- package/src/FireflyRuntime.tsx +8 -0
- package/src/index.ts +2 -1
- package/src/{boostrap.ts → initializeFirefly.ts} +38 -18
- package/src/useAppRouterStore.ts +8 -0
- package/src/useCanFetchProtectedData.ts +28 -12
- package/dist/boostrap.d.ts +0 -14
- package/dist/boostrap.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 12.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#252](https://github.com/workleap/wl-squide/pull/252) [`470252f`](https://github.com/workleap/wl-squide/commit/470252f11efe5d84a40e9c60c3bfc13d9f3bf049) Thanks [@patricklafrance](https://github.com/patricklafrance)! - The bootstrapping store wasn't in sync if the modules were initially either "registered" or "ready".
|
|
8
|
+
|
|
9
|
+
## 12.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [#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.
|
|
14
|
+
- The `FireflyRuntime` instance now expose a new `BootstrappingStore` instance.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`9429e98`](https://github.com/workleap/wl-squide/commit/9429e98382f054ed560297aa8a1e54caba40db4f), [`9429e98`](https://github.com/workleap/wl-squide/commit/9429e98382f054ed560297aa8a1e54caba40db4f)]:
|
|
19
|
+
- @squide/module-federation@6.2.5
|
|
20
|
+
- @squide/core@5.4.5
|
|
21
|
+
- @squide/msw@3.2.5
|
|
22
|
+
- @squide/react-router@7.0.3
|
|
23
|
+
|
|
3
24
|
## 11.0.0
|
|
4
25
|
|
|
5
26
|
### Major Changes
|
package/dist/AppRouter.d.ts
CHANGED
|
@@ -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 {
|
|
62
|
-
const [state, dispatch] = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterReducer_js_6fa81ecc__.useAppRouterReducer)(
|
|
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)(()=>{
|
package/dist/AppRouter.js.map
CHANGED
|
@@ -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
|
|
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(
|
|
41
|
+
export declare function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch];
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -2,6 +2,7 @@ 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
4
|
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useAppRouterStore_js_9635540d__ from "./useAppRouterStore.js";
|
|
5
6
|
import * as __WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__ from "./useExecuteOnce.js";
|
|
6
7
|
import * as __WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__ from "./useIsBootstrapping.js";
|
|
7
8
|
|
|
@@ -13,6 +14,8 @@ import * as __WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__ from "./
|
|
|
13
14
|
|
|
14
15
|
;// CONCATENATED MODULE: external "react"
|
|
15
16
|
|
|
17
|
+
;// CONCATENATED MODULE: external "./useAppRouterStore.js"
|
|
18
|
+
|
|
16
19
|
;// CONCATENATED MODULE: external "./useExecuteOnce.js"
|
|
17
20
|
|
|
18
21
|
;// CONCATENATED MODULE: external "./useIsBootstrapping.js"
|
|
@@ -24,11 +27,14 @@ import * as __WEBPACK_EXTERNAL_MODULE__useIsBootstrapping_js_642a9b43__ from "./
|
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
|
|
30
|
+
|
|
27
31
|
// The followings event const are a concatenation of "squide-" with AppRouterActionType.
|
|
28
32
|
// They are dispatched by the useEnhancedReducerDispatch hook.
|
|
29
33
|
const ModulesRegisteredEvent = "squide-modules-registered";
|
|
30
34
|
const ModulesReadyEvent = "squide-modules-ready";
|
|
31
35
|
const MswReadyEvent = "squide-msw-ready";
|
|
36
|
+
const ActiveRouteIsPublicEvent = "squide-active-route-is-public";
|
|
37
|
+
const ActiveRouteIsProtectedEvent = "squide-active-route-is-protected";
|
|
32
38
|
const PublicDataReadyEvent = "squide-public-data-ready";
|
|
33
39
|
const ProtectedDataReadyEvent = "squide-protected-data-ready";
|
|
34
40
|
const PublicDataUpdatedEvent = "squide-public-data-updated";
|
|
@@ -258,57 +264,74 @@ function useReducerDispatchProxy(reactDispatch) {
|
|
|
258
264
|
}
|
|
259
265
|
function useEnhancedReducerDispatch(reducerDispatch) {
|
|
260
266
|
const logger = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useLogger)();
|
|
267
|
+
const appRouterStore = (0,__WEBPACK_EXTERNAL_MODULE__useAppRouterStore_js_9635540d__.useAppRouterStore)();
|
|
261
268
|
const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useEventBus)();
|
|
262
269
|
return (0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)((action)=>{
|
|
263
270
|
logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
|
|
271
|
+
appRouterStore.dispatch(action);
|
|
264
272
|
eventBus.dispatch(`squide-${action.type}`);
|
|
265
273
|
reducerDispatch(action);
|
|
266
274
|
}, [
|
|
267
275
|
reducerDispatch,
|
|
268
276
|
logger,
|
|
277
|
+
appRouterStore,
|
|
269
278
|
eventBus
|
|
270
279
|
]);
|
|
271
280
|
}
|
|
272
|
-
function useAppRouterReducer(
|
|
281
|
+
function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
282
|
+
const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
|
|
283
|
+
const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useEventBus)();
|
|
284
|
+
const appRouterStore = (0,__WEBPACK_EXTERNAL_MODULE__useAppRouterStore_js_9635540d__.useAppRouterStore)();
|
|
273
285
|
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
274
286
|
const areModulesInitiallyReady = getAreModulesReady();
|
|
275
287
|
const isMswInitiallyReady = (0,__WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__.isMswReady)();
|
|
276
|
-
const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useEventBus)();
|
|
277
288
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
278
289
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
279
290
|
(0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
280
291
|
if (areModulesInitiallyRegistered) {
|
|
292
|
+
appRouterStore.dispatch({
|
|
293
|
+
type: "modules-registered"
|
|
294
|
+
});
|
|
281
295
|
eventBus.dispatch(ModulesRegisteredEvent);
|
|
282
296
|
}
|
|
283
297
|
return true;
|
|
284
298
|
}, [
|
|
285
299
|
areModulesInitiallyRegistered,
|
|
300
|
+
appRouterStore,
|
|
286
301
|
eventBus
|
|
287
302
|
]), true);
|
|
288
303
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
289
304
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
290
305
|
(0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
291
306
|
if (areModulesInitiallyReady) {
|
|
307
|
+
appRouterStore.dispatch({
|
|
308
|
+
type: "modules-ready"
|
|
309
|
+
});
|
|
292
310
|
eventBus.dispatch(ModulesReadyEvent);
|
|
293
311
|
}
|
|
294
312
|
return true;
|
|
295
313
|
}, [
|
|
296
314
|
areModulesInitiallyReady,
|
|
315
|
+
appRouterStore,
|
|
297
316
|
eventBus
|
|
298
317
|
]), true);
|
|
299
318
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
300
319
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
301
320
|
(0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
302
321
|
if (isMswInitiallyReady) {
|
|
322
|
+
appRouterStore.dispatch({
|
|
323
|
+
type: "msw-ready"
|
|
324
|
+
});
|
|
303
325
|
eventBus.dispatch(MswReadyEvent);
|
|
304
326
|
}
|
|
305
327
|
return true;
|
|
306
328
|
}, [
|
|
307
329
|
isMswInitiallyReady,
|
|
330
|
+
appRouterStore,
|
|
308
331
|
eventBus
|
|
309
332
|
]), true);
|
|
310
333
|
const [state, reactDispatch] = (0,__WEBPACK_EXTERNAL_MODULE_react__.useReducer)(reducer, {
|
|
311
|
-
waitForMsw,
|
|
334
|
+
waitForMsw: runtime.isMswEnabled,
|
|
312
335
|
waitForPublicData,
|
|
313
336
|
waitForProtectedData,
|
|
314
337
|
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
@@ -334,6 +357,6 @@ function useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData
|
|
|
334
357
|
];
|
|
335
358
|
}
|
|
336
359
|
|
|
337
|
-
export { ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useBootstrappingCompletedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
|
360
|
+
export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useBootstrappingCompletedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
|
338
361
|
|
|
339
362
|
//# 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,WA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tB;QAEA,OAAO;IACX,GAAG;QAAC6C;QAA+Bf;KAAS,GAAG;IAE/C,2IAA2I;IAC3I,6HAA6H;IAC7HhC,0EAAcA,CAACJ,iDAAWA,CAAC;QACvB,IAAIoD,0BAA0B;YAC1BhB,SAAS,QAAQ,CAAC7B;QACtB;QAEA,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 { useAppRouterStore } from \"./useAppRouterStore.ts\";\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 logger = useLogger();\n const appRouterStore = useAppRouterStore();\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\n appRouterStore.dispatch(action);\n eventBus.dispatch(`squide-${action.type}`);\n\n reducerDispatch(action);\n }, [reducerDispatch, logger, appRouterStore, eventBus]);\n}\n\nexport function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {\n const runtime = useRuntime() as FireflyRuntime;\n const eventBus = useEventBus();\n const appRouterStore = useAppRouterStore();\n\n const areModulesInitiallyRegistered = getAreModulesRegistered();\n const areModulesInitiallyReady = getAreModulesReady();\n const isMswInitiallyReady = isMswReady();\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 appRouterStore.dispatch({ type: \"modules-registered\" });\n eventBus.dispatch(ModulesRegisteredEvent);\n }\n\n return true;\n }, [areModulesInitiallyRegistered, appRouterStore, 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 appRouterStore.dispatch({ type: \"modules-ready\" });\n eventBus.dispatch(ModulesReadyEvent);\n }\n\n return true;\n }, [areModulesInitiallyReady, appRouterStore, 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 appRouterStore.dispatch({ type: \"msw-ready\" });\n eventBus.dispatch(MswReadyEvent);\n }\n\n return true;\n }, [isMswInitiallyReady, appRouterStore, 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","useAppRouterStore","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","appRouterStore","useAppRouterReducer","waitForPublicData","waitForProtectedData","runtime","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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QACtB;QAEA,OAAO;IACX,GAAG;QAACgD;QAA0BN;QAAgBX;KAAS,GAAG;IAE1D,2IAA2I;IAC3I,6HAA6H;IAC7HlC,0EAAcA,CAACL,iDAAWA,CAAC;QACvB,IAAIyD,qBAAqB;YACrBP,eAAe,QAAQ,CAAC;gBAAE,MAAM;YAAY;YAC5CX,SAAS,QAAQ,CAAC9B;QACtB;QAEA,OAAO;IACX,GAAG;QAACgD;QAAqBP;QAAgBX;KAAS,GAAG;IAErD,MAAM,CAACpB,OAAO4B,cAAc,GAAG5C,gDAAUA,CAACe,SAAS;QAC/C,YAAYoC,QAAQ,YAAY;QAChCF;QACAC;QACA,4HAA4H;QAC5H,sBAAsBE;QACtB,iBAAiBC;QACjB,YAAYC;QACZ,mBAAmB;QACnB,sBAAsB;QACtB,uBAAuB;QACvB,gBAAgB;IACpB;IAEA,MAAM,EACF,sBAAsB5B,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGjB;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAMuC,gBAAgBZ,wBAAwBC;IAC9C,MAAMhB,WAAWiB,2BAA2BU;IAE5C9B,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;I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AW;wBACP,GAAGA,QAAQ;wBACX,qBAAqBG,KAAK,GAAG;oBACjC;oBAEA;gBACJ;YACA,KAAK;gBAA0B;oBAC3BH,WAAW;wBACP,GAAGA,QAAQ;wBACX,wBAAwBG,KAAK,GAAG;oBACpC;oBAEA;gBACJ;YACA,KAAK;gBAAkC;oBACnCH,WAAW;wBACP,GAAGA,QAAQ;wBACX,gCAAgCG,KAAK,GAAG;oBAC5C;oBAEA;gBACJ;YACA,KAAK;gBAA0B;oBAC3BH,WAAW;wBACP,GAAGA,QAAQ;wBACX,uBAAuB;oBAC3B;oBAEA;gBACJ;YACA,KAAK;gBAA6B;oBAC9BA,WAAW;wBACP,GAAGA,QAAQ;wBACX,uBAAuB;oBAC3B;oBAEA;gBACJ;YACA,KAAK;gBAAmB;oBACpBA,WAAW;wBACP,GAAGA,QAAQ;wBACX,gBAAgB;oBACpB;oBAEA;gBACJ;YACA;gBAAS;oBACL,MAAM,IAAII,MAAM,CAAC,uEAAuE,EAAEL,OAAO,IAAI,CAAC,EAAE,CAAC;gBAC7G;QACJ;QAEA,OAAOC;IACX;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"}
|
package/dist/FireflyRuntime.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/FireflyRuntime.js
CHANGED
|
@@ -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":"
|
|
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","mswPlugin","Error","route"],"mappings":";;;;;;;;;;;;;;AACuD;AACe;AAEN;AACgB;AAMzE,MAAMK,uBAAuBH,4EAAkBA;IACzC,eAAe,CAAiB;IAChC,OAAO,CAAU;IAE1B,YAAY,EAAEI,OAAO,EAAEC,MAAM,EAAE,GAAGC,SAAgC,GAAG,CAAC,CAAC,CAAE;QACrE,IAAID,QAAQ;YACR,KAAK,CAAC;gBACF,SAAS;uBACDD,WAAW,EAAE;oBACjBG,CAAAA,UAAW,IAAIT,0DAASA,CAACS;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;QAEA,IAAI,CAAC,eAAe,GAAGJ,gFAAoBA,CAAC,IAAI,CAAC,OAAO;IAC5D;IAEA,wBAAwBM,QAA0B,EAAE;QAChD,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACV,8DAAaA;QAE9C,IAAI,CAACU,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,IAAIT,qFAAuBA,IAAI;YAC3B,MAAM,IAAIS,MAAM;QACpB;QAEAD,UAAU,uBAAuB,CAACD;IACtC;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACV,8DAAaA;QAE9C,IAAI,CAACU,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,UAAU,eAAe;IACpC;IAEA,cAAcE,KAAY,EAAEL,UAAgC,CAAC,CAAC,EAAE;QAC5D,IAAIL,qFAAuBA,IAAI;YAC3B,MAAM,IAAIS,MAAM;QACpB;QAEA,KAAK,CAAC,cAAcC,OAAOL;IAC/B;IAEA,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,eAAe;IAC/B;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,OAAO;IACvB;AACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./FireflyRuntime.tsx";
|
|
|
7
7
|
export * from "./AppRouter.tsx";
|
|
8
8
|
export * from "./AppRouterContext.ts";
|
|
9
9
|
export * from "./AppRouterReducer.ts";
|
|
10
|
+
export * from "./AppRouterStore.ts";
|
|
10
11
|
export * from "./GlobalDataQueriesError.ts";
|
|
11
12
|
export * from "./useCanFetchProtectedData.ts";
|
|
12
13
|
export * from "./useCanFetchPublicData.ts";
|
|
@@ -23,4 +24,4 @@ export * from "./usePublicDataQueries.ts";
|
|
|
23
24
|
export * from "./useRegisterDeferredRegistrations.ts";
|
|
24
25
|
export * from "./useStrictRegistrationMode.ts";
|
|
25
26
|
export * from "./useUpdateDeferredRegistrations.ts";
|
|
26
|
-
export * from "./
|
|
27
|
+
export * from "./initializeFirefly.ts";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./FireflyRuntime.js";
|
|
|
7
7
|
export * from "./AppRouter.js";
|
|
8
8
|
export * from "./AppRouterContext.js";
|
|
9
9
|
export * from "./AppRouterReducer.js";
|
|
10
|
+
export * from "./AppRouterStore.js";
|
|
10
11
|
export * from "./GlobalDataQueriesError.js";
|
|
11
12
|
export * from "./useCanFetchProtectedData.js";
|
|
12
13
|
export * from "./useCanFetchPublicData.js";
|
|
@@ -23,7 +24,7 @@ export * from "./usePublicDataQueries.js";
|
|
|
23
24
|
export * from "./useRegisterDeferredRegistrations.js";
|
|
24
25
|
export * from "./useStrictRegistrationMode.js";
|
|
25
26
|
export * from "./useUpdateDeferredRegistrations.js";
|
|
26
|
-
export * from "./
|
|
27
|
+
export * from "./initializeFirefly.js";
|
|
27
28
|
|
|
28
29
|
;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
|
|
29
30
|
|
|
@@ -52,6 +53,7 @@ export * from "./boostrap.js";
|
|
|
52
53
|
|
|
53
54
|
|
|
54
55
|
|
|
56
|
+
|
|
55
57
|
|
|
56
58
|
|
|
57
59
|
//# sourceMappingURL=index.js.map
|