@koordinates/xstate-tree 4.1.0-beta.3 → 4.1.0-beta.4
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/lib/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export * from "./slots";
|
|
|
3
3
|
export { broadcast, buildRootComponent, onBroadcast } from "./xstateTree";
|
|
4
4
|
export * from "./types";
|
|
5
5
|
export { buildTestRootComponent, buildViewProps, genericSlotsTestingDummy, slotTestingDummyFactory, } from "./testingUtilities";
|
|
6
|
-
export { Link, buildCreateRoute, matchRoute, } from "./routing";
|
|
6
|
+
export { Link, buildCreateRoute, matchRoute, useIsRouteActive, useRouteArgsIfActive, } from "./routing";
|
|
7
7
|
export { loggingMetaOptions } from "./useService";
|
|
8
8
|
export { lazy } from "./lazy";
|
package/lib/routing/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { Link } from "./Link";
|
|
|
4
4
|
export { matchRoute } from "./matchRoute";
|
|
5
5
|
export { handleLocationChange, } from "./handleLocationChange";
|
|
6
6
|
export { useIsRouteActive } from "./useIsRouteActive";
|
|
7
|
+
export { useRouteArgsIfActive } from "./useRouteArgsIfActive";
|
|
7
8
|
export { RoutingContext } from "./providers";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useActiveRouteEvents } from "./providers";
|
|
2
2
|
/**
|
|
3
|
+
* @public
|
|
3
4
|
* Accepts Routes and returns true if any route is currently active. False if not.
|
|
4
5
|
*
|
|
5
6
|
* If used outside of a RoutingContext, an error will be thrown.
|
|
6
7
|
* @param routes - the routes to check
|
|
7
8
|
* @returns true if any route is active, false if not
|
|
8
|
-
* @throws if used outside of
|
|
9
|
+
* @throws if used outside of an xstate-tree root
|
|
9
10
|
*/
|
|
10
11
|
export function useIsRouteActive(...routes) {
|
|
11
12
|
const activeRouteEvents = useActiveRouteEvents();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { assertIsDefined } from "../utils";
|
|
2
|
+
import { useActiveRouteEvents } from "./providers";
|
|
3
|
+
import { useIsRouteActive } from "./useIsRouteActive";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* Returns the arguments for the given route if the route is active.
|
|
7
|
+
* Returns undefined if the route is not active.
|
|
8
|
+
*
|
|
9
|
+
* @param route - the route to get the arguments for
|
|
10
|
+
* @returns the arguments for the given route if the route is active, undefined otherwise
|
|
11
|
+
* @throws if used outside of an xstate-tree root
|
|
12
|
+
*/
|
|
13
|
+
export function useRouteArgsIfActive(route) {
|
|
14
|
+
const isActive = useIsRouteActive(route);
|
|
15
|
+
const activeRoutes = useActiveRouteEvents();
|
|
16
|
+
if (!isActive) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const activeRoute = activeRoutes === null || activeRoutes === void 0 ? void 0 : activeRoutes.find((activeRoute) => activeRoute.type === route.event);
|
|
20
|
+
assertIsDefined(activeRoute, "active route is not defined, but the route is active??");
|
|
21
|
+
return {
|
|
22
|
+
params: activeRoute.params,
|
|
23
|
+
query: activeRoute.query,
|
|
24
|
+
meta: activeRoute.meta,
|
|
25
|
+
};
|
|
26
|
+
}
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -697,6 +697,28 @@ declare type States = {
|
|
|
697
697
|
*/
|
|
698
698
|
export declare type StyledLink<TStyleProps = {}> = <TRoute extends AnyRoute>(props: LinkProps<TRoute> & TStyleProps) => JSX.Element;
|
|
699
699
|
|
|
700
|
+
/**
|
|
701
|
+
* @public
|
|
702
|
+
* Accepts Routes and returns true if any route is currently active. False if not.
|
|
703
|
+
*
|
|
704
|
+
* If used outside of a RoutingContext, an error will be thrown.
|
|
705
|
+
* @param routes - the routes to check
|
|
706
|
+
* @returns true if any route is active, false if not
|
|
707
|
+
* @throws if used outside of an xstate-tree root
|
|
708
|
+
*/
|
|
709
|
+
export declare function useIsRouteActive(...routes: AnyRoute[]): boolean;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* @public
|
|
713
|
+
* Returns the arguments for the given route if the route is active.
|
|
714
|
+
* Returns undefined if the route is not active.
|
|
715
|
+
*
|
|
716
|
+
* @param route - the route to get the arguments for
|
|
717
|
+
* @returns the arguments for the given route if the route is active, undefined otherwise
|
|
718
|
+
* @throws if used outside of an xstate-tree root
|
|
719
|
+
*/
|
|
720
|
+
export declare function useRouteArgsIfActive<TRoute extends AnyRoute>(route: TRoute): ArgumentsForRoute<TRoute> | undefined;
|
|
721
|
+
|
|
700
722
|
/**
|
|
701
723
|
* @public
|
|
702
724
|
*/
|
package/package.json
CHANGED