@koordinates/xstate-tree 4.3.0-beta.9 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/index.js +2 -1
- package/lib/routing/index.js +2 -1
- package/lib/routing/providers.js +5 -0
- package/lib/utils.js +10 -1
- package/lib/xstate-tree.d.ts +14 -0
- package/lib/xstateTree.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ Each machine that forms the tree representing your UI has an associated set of s
|
|
|
140
140
|
To assist in making xstate-tree easy to use with TypeScript there is the `createXStateTreeMachine` function for typing selectors, actions and view arguments and stapling the resulting functions to the xstate machine
|
|
141
141
|
|
|
142
142
|
`createXStateTreeMachine` accepts the xstate machine as the first argument and takes an options argument with the following fields, it is important the fields are defined in this order or TypeScript will infer the wrong types:
|
|
143
|
-
* `selectors`, receives an object with `ctx`, `inState`, and `
|
|
143
|
+
* `selectors`, receives an object with `ctx`, `inState`, `canHandleEvent`, and `meta` fields. `ctx` is the machines current context, `inState` is the xstate `state.matches` function to allow determining if the machine is in a given state, and `canHandleEvent` accepts an event object and returns whether the machine will do anything in response to that event in it's current state. `meta` is the xstate `state.meta` object with all the per state meta flattened into an object
|
|
144
144
|
* `actions`, receives an object with `send` and `selectors` fields. `send` is the xstate `send` function bound to the machine, and `selectors` is the result of calling the selector function
|
|
145
145
|
* `view`, is a React component that receives `actions`, `selectors`, and `slots` as props. `actions` and `selectors` being the result of the action/selector functions and `slots` being an object with keys as the slot names and the values the slots React component
|
|
146
146
|
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.lazy = exports.loggingMetaOptions = exports.TestRoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.matchRoute = exports.buildCreateRoute = exports.Link = exports.slotTestingDummyFactory = exports.genericSlotsTestingDummy = exports.buildViewProps = exports.buildTestRootComponent = exports.onBroadcast = exports.buildRootComponent = exports.broadcast = void 0;
|
|
17
|
+
exports.lazy = exports.loggingMetaOptions = exports.TestRoutingContext = exports.useActiveRouteEvents = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.matchRoute = exports.buildCreateRoute = exports.Link = exports.slotTestingDummyFactory = exports.genericSlotsTestingDummy = exports.buildViewProps = exports.buildTestRootComponent = exports.onBroadcast = exports.buildRootComponent = exports.broadcast = void 0;
|
|
18
18
|
__exportStar(require("./builders"), exports);
|
|
19
19
|
__exportStar(require("./slots"), exports);
|
|
20
20
|
var xstateTree_1 = require("./xstateTree");
|
|
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "buildCreateRoute", { enumerable: true, get: func
|
|
|
33
33
|
Object.defineProperty(exports, "matchRoute", { enumerable: true, get: function () { return routing_1.matchRoute; } });
|
|
34
34
|
Object.defineProperty(exports, "useIsRouteActive", { enumerable: true, get: function () { return routing_1.useIsRouteActive; } });
|
|
35
35
|
Object.defineProperty(exports, "useRouteArgsIfActive", { enumerable: true, get: function () { return routing_1.useRouteArgsIfActive; } });
|
|
36
|
+
Object.defineProperty(exports, "useActiveRouteEvents", { enumerable: true, get: function () { return routing_1.useActiveRouteEvents; } });
|
|
36
37
|
Object.defineProperty(exports, "TestRoutingContext", { enumerable: true, get: function () { return routing_1.TestRoutingContext; } });
|
|
37
38
|
var useService_1 = require("./useService");
|
|
38
39
|
Object.defineProperty(exports, "loggingMetaOptions", { enumerable: true, get: function () { return useService_1.loggingMetaOptions; } });
|
package/lib/routing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useInRoutingContext = exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
|
|
3
|
+
exports.useActiveRouteEvents = exports.useInRoutingContext = exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
|
|
4
4
|
var createRoute_1 = require("./createRoute");
|
|
5
5
|
Object.defineProperty(exports, "buildCreateRoute", { enumerable: true, get: function () { return createRoute_1.buildCreateRoute; } });
|
|
6
6
|
var joinRoutes_1 = require("./joinRoutes");
|
|
@@ -19,3 +19,4 @@ var providers_1 = require("./providers");
|
|
|
19
19
|
Object.defineProperty(exports, "RoutingContext", { enumerable: true, get: function () { return providers_1.RoutingContext; } });
|
|
20
20
|
Object.defineProperty(exports, "TestRoutingContext", { enumerable: true, get: function () { return providers_1.TestRoutingContext; } });
|
|
21
21
|
Object.defineProperty(exports, "useInRoutingContext", { enumerable: true, get: function () { return providers_1.useInRoutingContext; } });
|
|
22
|
+
Object.defineProperty(exports, "useActiveRouteEvents", { enumerable: true, get: function () { return providers_1.useActiveRouteEvents; } });
|
package/lib/routing/providers.js
CHANGED
|
@@ -22,6 +22,11 @@ function useInRoutingContext() {
|
|
|
22
22
|
return context !== undefined;
|
|
23
23
|
}
|
|
24
24
|
exports.useInRoutingContext = useInRoutingContext;
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*
|
|
28
|
+
* Returns the list of active routing events, or undefined if there are none / used outside of an xstate-tree routing context
|
|
29
|
+
*/
|
|
25
30
|
function useActiveRouteEvents() {
|
|
26
31
|
var _a;
|
|
27
32
|
try {
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNil = exports.isEqual = exports.difference = exports.isLikelyPageLoad = exports.assert = exports.assertIsDefined = exports.delay = void 0;
|
|
3
|
+
exports.mergeMeta = exports.isNil = exports.isEqual = exports.difference = exports.isLikelyPageLoad = exports.assert = exports.assertIsDefined = exports.delay = void 0;
|
|
4
4
|
function delay(ms = 0) {
|
|
5
5
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
6
|
}
|
|
@@ -121,3 +121,12 @@ value) {
|
|
|
121
121
|
return value === null || value === undefined;
|
|
122
122
|
}
|
|
123
123
|
exports.isNil = isNil;
|
|
124
|
+
function mergeMeta(meta) {
|
|
125
|
+
return Object.keys(meta).reduce((acc, key) => {
|
|
126
|
+
const value = meta[key];
|
|
127
|
+
// Assuming each meta value is an object
|
|
128
|
+
Object.assign(acc, value);
|
|
129
|
+
return acc;
|
|
130
|
+
}, {});
|
|
131
|
+
}
|
|
132
|
+
exports.mergeMeta = mergeMeta;
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -658,6 +658,7 @@ export declare type Selectors<TMachine extends AnyStateMachine, TOut> = (args: {
|
|
|
658
658
|
ctx: ContextFrom<TMachine>;
|
|
659
659
|
canHandleEvent: CanHandleEvent<TMachine>;
|
|
660
660
|
inState: MatchesFrom<TMachine>;
|
|
661
|
+
meta?: unknown;
|
|
661
662
|
}) => TOut;
|
|
662
663
|
|
|
663
664
|
/**
|
|
@@ -762,6 +763,19 @@ export declare function TestRoutingContext({ activeRouteEvents, children, }: {
|
|
|
762
763
|
children: React_2.ReactNode;
|
|
763
764
|
}): JSX.Element;
|
|
764
765
|
|
|
766
|
+
/**
|
|
767
|
+
* @public
|
|
768
|
+
*
|
|
769
|
+
* Returns the list of active routing events, or undefined if there are none / used outside of an xstate-tree routing context
|
|
770
|
+
*/
|
|
771
|
+
export declare function useActiveRouteEvents(): {
|
|
772
|
+
type: unknown;
|
|
773
|
+
originalUrl: string;
|
|
774
|
+
params: unknown;
|
|
775
|
+
query: unknown;
|
|
776
|
+
meta: unknown;
|
|
777
|
+
}[] | undefined;
|
|
778
|
+
|
|
765
779
|
/**
|
|
766
780
|
* @public
|
|
767
781
|
* Accepts Routes and returns true if any route is currently active. False if not.
|
package/lib/xstateTree.js
CHANGED
package/package.json
CHANGED