@squide/firefly 13.0.1 → 13.0.3
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 +18 -0
- package/dist/AppRouter.js +17 -17
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterContext.js +8 -8
- package/dist/AppRouterContext.js.map +1 -1
- package/dist/AppRouterReducer.js +47 -47
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/FireflyProvider.js +3 -3
- package/dist/FireflyProvider.js.map +1 -1
- package/dist/FireflyRuntime.js +11 -11
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/RootRoute.js +10 -10
- package/dist/RootRoute.js.map +1 -1
- package/dist/honeycomb/activeSpan.js +6 -6
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/dist/honeycomb/initializeHoneycomb.js +2 -2
- package/dist/honeycomb/initializeHoneycomb.js.map +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.d.ts +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.js +97 -73
- package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
- package/dist/honeycomb/tracer.js +2 -2
- package/dist/honeycomb/tracer.js.map +1 -1
- package/dist/honeycomb/utils.js +12 -12
- package/dist/honeycomb/utils.js.map +1 -1
- package/dist/initializeFirefly.js +11 -11
- package/dist/initializeFirefly.js.map +1 -1
- package/dist/useAppRouterStore.js +2 -2
- package/dist/useAppRouterStore.js.map +1 -1
- package/dist/useCanFetchProtectedData.js +2 -2
- package/dist/useCanFetchProtectedData.js.map +1 -1
- package/dist/useCanFetchPublicData.js +2 -2
- package/dist/useCanFetchPublicData.js.map +1 -1
- package/dist/useCanRegisterDeferredRegistrations.js +2 -2
- package/dist/useCanRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useCanUpdateDeferredRegistrations.js +2 -2
- package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
- package/dist/useDeferredRegistrations.js +13 -13
- package/dist/useDeferredRegistrations.js.map +1 -1
- package/dist/useExecuteOnce.js +3 -3
- package/dist/useExecuteOnce.js.map +1 -1
- package/dist/useIsActiveRouteProtected.js +5 -5
- package/dist/useIsActiveRouteProtected.js.map +1 -1
- package/dist/useIsBootstrapping.js +2 -2
- package/dist/useIsBootstrapping.js.map +1 -1
- package/dist/useNavigationItems.js +4 -4
- package/dist/useNavigationItems.js.map +1 -1
- package/dist/useProtectedDataHandler.js +4 -4
- package/dist/useProtectedDataHandler.js.map +1 -1
- package/dist/useProtectedDataQueries.js +20 -20
- package/dist/useProtectedDataQueries.js.map +1 -1
- package/dist/usePublicDataHandler.js +4 -4
- package/dist/usePublicDataHandler.js.map +1 -1
- package/dist/usePublicDataQueries.js +19 -19
- package/dist/usePublicDataQueries.js.map +1 -1
- package/dist/useRegisterDeferredRegistrations.js +4 -4
- package/dist/useRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useStrictRegistrationMode.js +12 -12
- package/dist/useStrictRegistrationMode.js.map +1 -1
- package/dist/useUpdateDeferredRegistrations.js +6 -6
- package/dist/useUpdateDeferredRegistrations.js.map +1 -1
- package/package.json +16 -16
- package/src/honeycomb/registerHoneycombInstrumentation.ts +35 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 13.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#291](https://github.com/workleap/wl-squide/pull/291) [`f0ed2f2`](https://github.com/workleap/wl-squide/commit/f0ed2f2f226e5e614fab05b8affdcebb94dd2755) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Remove redundant error tracing with Honeycomb instrumentation.
|
|
8
|
+
|
|
9
|
+
## 13.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#289](https://github.com/workleap/wl-squide/pull/289) [`ee6f7d5`](https://github.com/workleap/wl-squide/commit/ee6f7d52ff6afa8ac757770c89b39978c40a70bc) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Fixed Honeycomb telemetry traces when data fetching fails and bumped dependencies versions.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`ee6f7d5`](https://github.com/workleap/wl-squide/commit/ee6f7d52ff6afa8ac757770c89b39978c40a70bc)]:
|
|
16
|
+
- @squide/module-federation@6.2.9
|
|
17
|
+
- @squide/react-router@7.0.7
|
|
18
|
+
- @squide/core@5.4.9
|
|
19
|
+
- @squide/msw@3.2.9
|
|
20
|
+
|
|
3
21
|
## 13.0.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/AppRouter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLogger } from "@squide/core";
|
|
3
|
+
import { useRoutes } from "@squide/react-router";
|
|
4
|
+
import { useEffect, useMemo } from "react";
|
|
5
|
+
import { AppRouterDispatcherContext, AppRouterStateContext } from "./AppRouterContext.js";
|
|
6
|
+
import { useAppRouterReducer } from "./AppRouterReducer.js";
|
|
7
|
+
import { RootRoute } from "./RootRoute.js";
|
|
8
|
+
import { useStrictRegistrationMode } from "./useStrictRegistrationMode.js";
|
|
9
9
|
|
|
10
10
|
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
11
11
|
|
|
@@ -38,14 +38,14 @@ function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesR
|
|
|
38
38
|
areModulesRegistered || areModulesReadyValue);
|
|
39
39
|
}
|
|
40
40
|
function useRenderRouterProvider(state, renderRouterProvider) {
|
|
41
|
-
const routes =
|
|
41
|
+
const routes = useRoutes();
|
|
42
42
|
// The value is computed outside of the router provider memo to prevent
|
|
43
43
|
// rendering a new router provider everytime the app router state change.
|
|
44
44
|
const canRenderRouter = useCanRenderRouter(state);
|
|
45
|
-
return
|
|
45
|
+
return useMemo(()=>{
|
|
46
46
|
if (canRenderRouter) {
|
|
47
47
|
return renderRouterProvider({
|
|
48
|
-
rootRoute: /*#__PURE__*/
|
|
48
|
+
rootRoute: /*#__PURE__*/ jsx(RootRoute, {}),
|
|
49
49
|
registeredRoutes: routes,
|
|
50
50
|
routerProviderProps: {}
|
|
51
51
|
});
|
|
@@ -59,19 +59,19 @@ function useRenderRouterProvider(state, renderRouterProvider) {
|
|
|
59
59
|
}
|
|
60
60
|
function AppRouter(props) {
|
|
61
61
|
const { waitForPublicData = false, waitForProtectedData = false, children: renderRouterProvider } = props;
|
|
62
|
-
const [state, dispatch] =
|
|
63
|
-
const logger =
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);
|
|
63
|
+
const logger = useLogger();
|
|
64
|
+
useStrictRegistrationMode();
|
|
65
|
+
useEffect(()=>{
|
|
66
66
|
logger.debug("[squide] AppRouter state updated:", state);
|
|
67
67
|
}, [
|
|
68
68
|
state,
|
|
69
69
|
logger
|
|
70
70
|
]);
|
|
71
71
|
const routerProvider = useRenderRouterProvider(state, renderRouterProvider);
|
|
72
|
-
return /*#__PURE__*/
|
|
72
|
+
return /*#__PURE__*/ jsx(AppRouterDispatcherContext.Provider, {
|
|
73
73
|
value: dispatch,
|
|
74
|
-
children: /*#__PURE__*/
|
|
74
|
+
children: /*#__PURE__*/ jsx(AppRouterStateContext.Provider, {
|
|
75
75
|
value: state,
|
|
76
76
|
children: routerProvider
|
|
77
77
|
})
|
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 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,
|
|
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,SAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMe,kBAAkBP,mBAAmBI;IAE3C,OAAOV,OAAOA,CAAC;QACX,IAAIa,iBAAiB;YACjB,OAAOF,qBAAqB;gBACxB,yBAAW,IAACP,SAASA;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,mBAAmBA,CAACa,mBAAmBC;IAEjE,MAAME,SAAStB,SAASA;IAExBQ,yBAAyBA;IAEzBN,SAASA,CAAC;QACNoB,OAAO,KAAK,CAAC,qCAAqCT;IACtD,GAAG;QAACA;QAAOS;KAAO;IAElB,MAAMC,iBAAiBX,wBAAwBC,OAAOC;IAEtD,qBACI,IAACV,mCAAmC;QAAC,OAAOiB;kBACxC,kBAAChB,8BAA8B;YAAC,OAAOQ;sBAClCU;;;AAIjB"}
|
package/dist/AppRouterContext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { isNil } from "@squide/core";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
3
|
|
|
4
4
|
;// CONCATENATED MODULE: external "@squide/core"
|
|
5
5
|
|
|
@@ -8,18 +8,18 @@ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
|
8
8
|
;// CONCATENATED MODULE: ./src/AppRouterContext.ts
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
const AppRouterStateContext =
|
|
11
|
+
const AppRouterStateContext = createContext(undefined);
|
|
12
12
|
function useAppRouterState() {
|
|
13
|
-
const state =
|
|
14
|
-
if (
|
|
13
|
+
const state = useContext(AppRouterStateContext);
|
|
14
|
+
if (isNil(state)) {
|
|
15
15
|
throw new Error("[squide] The useAppRouterState hook must be called by a children of the AppRouter component.");
|
|
16
16
|
}
|
|
17
17
|
return state;
|
|
18
18
|
}
|
|
19
|
-
const AppRouterDispatcherContext =
|
|
19
|
+
const AppRouterDispatcherContext = createContext(undefined);
|
|
20
20
|
function useAppRouterDispatcher() {
|
|
21
|
-
const dispatch =
|
|
22
|
-
if (
|
|
21
|
+
const dispatch = useContext(AppRouterDispatcherContext);
|
|
22
|
+
if (isNil(dispatch)) {
|
|
23
23
|
throw new Error("[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.");
|
|
24
24
|
}
|
|
25
25
|
return dispatch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterContext.js","sources":["webpack://@squide/firefly/./src/AppRouterContext.ts"],"sourcesContent":["import { isNil } from \"@squide/core\";\nimport { createContext, useContext } from \"react\";\nimport type { AppRouterDispatch, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport const AppRouterStateContext = createContext<AppRouterState | undefined>(undefined);\n\nexport function useAppRouterState() {\n const state = useContext(AppRouterStateContext);\n\n if (isNil(state)) {\n throw new Error(\"[squide] The useAppRouterState hook must be called by a children of the AppRouter component.\");\n }\n\n return state;\n}\n\nexport const AppRouterDispatcherContext = createContext<AppRouterDispatch | undefined>(undefined);\n\nexport function useAppRouterDispatcher() {\n const dispatch = useContext(AppRouterDispatcherContext);\n\n if (isNil(dispatch)) {\n throw new Error(\"[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.\");\n }\n\n return dispatch;\n}\n"],"names":["isNil","createContext","useContext","AppRouterStateContext","undefined","useAppRouterState","state","Error","AppRouterDispatcherContext","useAppRouterDispatcher","dispatch"],"mappings":";;;;;;;;AAAqC;AACa;AAG3C,MAAMG,wBAAwBF,
|
|
1
|
+
{"version":3,"file":"AppRouterContext.js","sources":["webpack://@squide/firefly/./src/AppRouterContext.ts"],"sourcesContent":["import { isNil } from \"@squide/core\";\nimport { createContext, useContext } from \"react\";\nimport type { AppRouterDispatch, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport const AppRouterStateContext = createContext<AppRouterState | undefined>(undefined);\n\nexport function useAppRouterState() {\n const state = useContext(AppRouterStateContext);\n\n if (isNil(state)) {\n throw new Error(\"[squide] The useAppRouterState hook must be called by a children of the AppRouter component.\");\n }\n\n return state;\n}\n\nexport const AppRouterDispatcherContext = createContext<AppRouterDispatch | undefined>(undefined);\n\nexport function useAppRouterDispatcher() {\n const dispatch = useContext(AppRouterDispatcherContext);\n\n if (isNil(dispatch)) {\n throw new Error(\"[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.\");\n }\n\n return dispatch;\n}\n"],"names":["isNil","createContext","useContext","AppRouterStateContext","undefined","useAppRouterState","state","Error","AppRouterDispatcherContext","useAppRouterDispatcher","dispatch"],"mappings":";;;;;;;;AAAqC;AACa;AAG3C,MAAMG,wBAAwBF,aAAaA,CAA6BG,WAAW;AAEnF,SAASC;IACZ,MAAMC,QAAQJ,UAAUA,CAACC;IAEzB,IAAIH,KAAKA,CAACM,QAAQ;QACd,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX;AAEO,MAAME,6BAA6BP,aAAaA,CAAgCG,WAAW;AAE3F,SAASK;IACZ,MAAMC,WAAWR,UAAUA,CAACM;IAE5B,IAAIR,KAAKA,CAACU,WAAW;QACjB,MAAM,IAAIH,MAAM;IACpB;IAEA,OAAOG;AACX"}
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger, useRuntime } from "@squide/core";
|
|
2
|
+
import { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from "@squide/module-federation";
|
|
3
|
+
import { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from "@squide/msw";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useReducer } from "react";
|
|
5
|
+
import { useAppRouterStore } from "./useAppRouterStore.js";
|
|
6
|
+
import { useExecuteOnce } from "./useExecuteOnce.js";
|
|
7
|
+
import { isBootstrapping } from "./useIsBootstrapping.js";
|
|
8
8
|
|
|
9
9
|
;// CONCATENATED MODULE: external "@squide/core"
|
|
10
10
|
|
|
@@ -144,18 +144,18 @@ function reducer(state, action) {
|
|
|
144
144
|
return newState;
|
|
145
145
|
}
|
|
146
146
|
function getAreModulesRegistered() {
|
|
147
|
-
const localModuleStatus =
|
|
148
|
-
const remoteModuleStatus =
|
|
149
|
-
return
|
|
147
|
+
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
148
|
+
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
149
|
+
return areModulesRegistered(localModuleStatus, remoteModuleStatus);
|
|
150
150
|
}
|
|
151
151
|
function getAreModulesReady() {
|
|
152
|
-
const localModuleStatus =
|
|
153
|
-
const remoteModuleStatus =
|
|
154
|
-
return
|
|
152
|
+
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
153
|
+
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
154
|
+
return areModulesReady(localModuleStatus, remoteModuleStatus);
|
|
155
155
|
}
|
|
156
156
|
function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch) {
|
|
157
|
-
const logger =
|
|
158
|
-
const dispatchModulesRegistered =
|
|
157
|
+
const logger = useLogger();
|
|
158
|
+
const dispatchModulesRegistered = useExecuteOnce(useCallback(()=>{
|
|
159
159
|
if (getAreModulesRegistered()) {
|
|
160
160
|
dispatch({
|
|
161
161
|
type: "modules-registered"
|
|
@@ -168,7 +168,7 @@ function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areMod
|
|
|
168
168
|
dispatch,
|
|
169
169
|
logger
|
|
170
170
|
]));
|
|
171
|
-
const dispatchModulesReady =
|
|
171
|
+
const dispatchModulesReady = useExecuteOnce(useCallback(()=>{
|
|
172
172
|
if (getAreModulesReady()) {
|
|
173
173
|
dispatch({
|
|
174
174
|
type: "modules-ready"
|
|
@@ -181,20 +181,20 @@ function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areMod
|
|
|
181
181
|
dispatch,
|
|
182
182
|
logger
|
|
183
183
|
]));
|
|
184
|
-
return
|
|
184
|
+
return useEffect(()=>{
|
|
185
185
|
if (!areModulesRegisteredValue) {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
187
|
+
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
188
188
|
}
|
|
189
189
|
if (!areModulesReadyValue) {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
191
|
+
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
192
192
|
}
|
|
193
193
|
return ()=>{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
195
|
+
removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
196
|
+
removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
197
|
+
removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
198
198
|
};
|
|
199
199
|
}, [
|
|
200
200
|
areModulesRegisteredValue,
|
|
@@ -204,9 +204,9 @@ function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areMod
|
|
|
204
204
|
]);
|
|
205
205
|
}
|
|
206
206
|
function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
207
|
-
const logger =
|
|
208
|
-
const dispatchMswReady =
|
|
209
|
-
if (
|
|
207
|
+
const logger = useLogger();
|
|
208
|
+
const dispatchMswReady = useExecuteOnce(useCallback(()=>{
|
|
209
|
+
if (isMswReady()) {
|
|
210
210
|
dispatch({
|
|
211
211
|
type: "msw-ready"
|
|
212
212
|
});
|
|
@@ -218,12 +218,12 @@ function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
|
218
218
|
dispatch,
|
|
219
219
|
logger
|
|
220
220
|
]));
|
|
221
|
-
|
|
221
|
+
useEffect(()=>{
|
|
222
222
|
if (!isMswReadyValue) {
|
|
223
|
-
|
|
223
|
+
addMswStateChangedListener(dispatchMswReady);
|
|
224
224
|
}
|
|
225
225
|
return ()=>{
|
|
226
|
-
|
|
226
|
+
removeMswStateChangedListener(dispatchMswReady);
|
|
227
227
|
};
|
|
228
228
|
}, [
|
|
229
229
|
isMswReadyValue,
|
|
@@ -231,10 +231,10 @@ function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
|
231
231
|
]);
|
|
232
232
|
}
|
|
233
233
|
function useBootstrappingCompletedDispatcher(state) {
|
|
234
|
-
const eventBus =
|
|
234
|
+
const eventBus = useEventBus();
|
|
235
235
|
const areModulesRegisteredValue = state.areModulesRegistered;
|
|
236
|
-
const isBoostrapping =
|
|
237
|
-
|
|
236
|
+
const isBoostrapping = isBootstrapping(state);
|
|
237
|
+
useExecuteOnce(useCallback(()=>{
|
|
238
238
|
if (areModulesRegisteredValue && !isBoostrapping) {
|
|
239
239
|
eventBus.dispatch(ApplicationBoostrappedEvent);
|
|
240
240
|
return true;
|
|
@@ -256,17 +256,17 @@ function __clearAppReducerDispatchProxy() {
|
|
|
256
256
|
dispatchProxyFactory = undefined;
|
|
257
257
|
}
|
|
258
258
|
function useReducerDispatchProxy(reactDispatch) {
|
|
259
|
-
return
|
|
259
|
+
return useMemo(()=>{
|
|
260
260
|
return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;
|
|
261
261
|
}, [
|
|
262
262
|
reactDispatch
|
|
263
263
|
]);
|
|
264
264
|
}
|
|
265
265
|
function useEnhancedReducerDispatch(reducerDispatch) {
|
|
266
|
-
const logger =
|
|
267
|
-
const appRouterStore =
|
|
268
|
-
const eventBus =
|
|
269
|
-
return
|
|
266
|
+
const logger = useLogger();
|
|
267
|
+
const appRouterStore = useAppRouterStore();
|
|
268
|
+
const eventBus = useEventBus();
|
|
269
|
+
return useCallback((action)=>{
|
|
270
270
|
logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
|
|
271
271
|
appRouterStore.dispatch(action);
|
|
272
272
|
eventBus.dispatch(`squide-${action.type}`);
|
|
@@ -279,15 +279,15 @@ function useEnhancedReducerDispatch(reducerDispatch) {
|
|
|
279
279
|
]);
|
|
280
280
|
}
|
|
281
281
|
function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
282
|
-
const runtime =
|
|
283
|
-
const eventBus =
|
|
284
|
-
const appRouterStore =
|
|
282
|
+
const runtime = useRuntime();
|
|
283
|
+
const eventBus = useEventBus();
|
|
284
|
+
const appRouterStore = useAppRouterStore();
|
|
285
285
|
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
286
286
|
const areModulesInitiallyReady = getAreModulesReady();
|
|
287
|
-
const isMswInitiallyReady =
|
|
287
|
+
const isMswInitiallyReady = isMswReady();
|
|
288
288
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
289
289
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
290
|
-
|
|
290
|
+
useExecuteOnce(useCallback(()=>{
|
|
291
291
|
if (areModulesInitiallyRegistered) {
|
|
292
292
|
appRouterStore.dispatch({
|
|
293
293
|
type: "modules-registered"
|
|
@@ -302,7 +302,7 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
302
302
|
]), true);
|
|
303
303
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
304
304
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
305
|
-
|
|
305
|
+
useExecuteOnce(useCallback(()=>{
|
|
306
306
|
if (areModulesInitiallyReady) {
|
|
307
307
|
appRouterStore.dispatch({
|
|
308
308
|
type: "modules-ready"
|
|
@@ -317,7 +317,7 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
317
317
|
]), true);
|
|
318
318
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
319
319
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
320
|
-
|
|
320
|
+
useExecuteOnce(useCallback(()=>{
|
|
321
321
|
if (isMswInitiallyReady) {
|
|
322
322
|
appRouterStore.dispatch({
|
|
323
323
|
type: "msw-ready"
|
|
@@ -330,7 +330,7 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
330
330
|
appRouterStore,
|
|
331
331
|
eventBus
|
|
332
332
|
]), true);
|
|
333
|
-
const [state, reactDispatch] =
|
|
333
|
+
const [state, reactDispatch] = useReducer(reducer, {
|
|
334
334
|
waitForMsw: runtime.isMswEnabled,
|
|
335
335
|
waitForPublicData,
|
|
336
336
|
waitForProtectedData,
|
|
@@ -1 +1 @@
|
|
|
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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AChDX,SAAS,QAAQ,CAAC/B;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"}
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;AAAyM;AACmB;AACxH;AACjB;AAExB;AACN;AACK;AAiC1D,wFAAwF;AACxF,8DAA8D;AACv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AcA,CAACL,WAAWA,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,UAAUA,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"}
|
package/dist/FireflyProvider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeContext } from "@squide/core";
|
|
3
3
|
|
|
4
4
|
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core
|
|
|
10
10
|
|
|
11
11
|
function FireflyProvider(props) {
|
|
12
12
|
const { runtime, children } = props;
|
|
13
|
-
return /*#__PURE__*/
|
|
13
|
+
return /*#__PURE__*/ jsx(RuntimeContext.Provider, {
|
|
14
14
|
value: runtime,
|
|
15
15
|
children: children
|
|
16
16
|
});
|
|
@@ -1 +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
|
|
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,IAACF,uBAAuB;QAAC,OAAOG;kBAC3BC;;AAGb"}
|
package/dist/FireflyRuntime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
2
|
+
import { ReactRouterRuntime } from "@squide/react-router";
|
|
3
|
+
import { getAreModulesRegistered } from "./AppRouterReducer.js";
|
|
4
|
+
import { createAppRouterStore } from "./AppRouterStore.js";
|
|
5
5
|
|
|
6
6
|
;// CONCATENATED MODULE: external "@squide/msw"
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__AppRouterStore_js_e9778a35__ from "./AppR
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class FireflyRuntime extends
|
|
19
|
+
class FireflyRuntime extends ReactRouterRuntime {
|
|
20
20
|
#appRouterStore;
|
|
21
21
|
#useMsw;
|
|
22
22
|
constructor({ plugins, useMsw, ...options } = {}){
|
|
@@ -24,7 +24,7 @@ class FireflyRuntime extends __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a
|
|
|
24
24
|
super({
|
|
25
25
|
plugins: [
|
|
26
26
|
...plugins ?? [],
|
|
27
|
-
(runtime)=>new
|
|
27
|
+
(runtime)=>new MswPlugin(runtime)
|
|
28
28
|
],
|
|
29
29
|
...options
|
|
30
30
|
});
|
|
@@ -36,28 +36,28 @@ class FireflyRuntime extends __WEBPACK_EXTERNAL_MODULE__squide_react_router_299a
|
|
|
36
36
|
});
|
|
37
37
|
this.#useMsw = false;
|
|
38
38
|
}
|
|
39
|
-
this.#appRouterStore =
|
|
39
|
+
this.#appRouterStore = createAppRouterStore(this._logger);
|
|
40
40
|
}
|
|
41
41
|
registerRequestHandlers(handlers) {
|
|
42
|
-
const mswPlugin = this.getPlugin(
|
|
42
|
+
const mswPlugin = this.getPlugin(MswPluginName);
|
|
43
43
|
if (!mswPlugin) {
|
|
44
44
|
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?");
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
46
|
+
if (getAreModulesRegistered()) {
|
|
47
47
|
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.");
|
|
48
48
|
}
|
|
49
49
|
mswPlugin.registerRequestHandlers(handlers);
|
|
50
50
|
}
|
|
51
51
|
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
52
52
|
get requestHandlers() {
|
|
53
|
-
const mswPlugin = this.getPlugin(
|
|
53
|
+
const mswPlugin = this.getPlugin(MswPluginName);
|
|
54
54
|
if (!mswPlugin) {
|
|
55
55
|
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?");
|
|
56
56
|
}
|
|
57
57
|
return mswPlugin.requestHandlers;
|
|
58
58
|
}
|
|
59
59
|
registerRoute(route, options = {}) {
|
|
60
|
-
if (
|
|
60
|
+
if (getAreModulesRegistered()) {
|
|
61
61
|
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.");
|
|
62
62
|
}
|
|
63
63
|
super.registerRoute(route, options);
|
|
@@ -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\";\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,
|
|
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,kBAAkBA;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,SAASA,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,oBAAoBA,CAAC,IAAI,CAAC,OAAO;IAC5D;IAEA,wBAAwBM,QAA0B,EAAE;QAChD,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACV,aAAaA;QAE9C,IAAI,CAACU,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,IAAIT,uBAAuBA,IAAI;YAC3B,MAAM,IAAIS,MAAM;QACpB;QAEAD,UAAU,uBAAuB,CAACD;IACtC;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACV,aAAaA;QAE9C,IAAI,CAACU,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,OA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