@koordinates/xstate-tree 4.1.2 → 4.1.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/README.md +3 -3
- package/lib/testingUtilities.js +2 -1
- package/lib/xstate-tree.d.ts +1 -1
- package/lib/xstateTree.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ While xstate-tree manages your application state, it does not have a mechanism f
|
|
|
15
15
|
|
|
16
16
|
At Koordinates we use xstate-tree for all new UI development. Our desktop application, built on top of [Kart](https://kartproject.org/) our Geospatial version control system, is built entirely with xstate-tree using GraphQL for global state.
|
|
17
17
|
|
|
18
|
-
A minimal example of a single machine tree
|
|
18
|
+
A minimal example of a single machine tree:
|
|
19
19
|
|
|
20
20
|
```tsx
|
|
21
21
|
import React from "react";
|
|
@@ -155,7 +155,7 @@ Slotted machines are determined based on the id of the invoked/spawned machine.
|
|
|
155
155
|
`singleSlot` accepts the name of the slot as the first argument and returns an object with a method `getId()` that returns the id of the slot.
|
|
156
156
|
`multiSlot` accepts the name of the slot and returns an object with a method `getId(id: string)` that returns the id of the slot
|
|
157
157
|
|
|
158
|
-
You should always use the `getId` methods when invoking/spawning something into a slot. Each slot the machine has must be represented by a call to `singleSlot` or `multiSlot` and stored into an array of slots. These slots must be passed to the `
|
|
158
|
+
You should always use the `getId` methods when invoking/spawning something into a slot. Each slot the machine has must be represented by a call to `singleSlot` or `multiSlot` and stored into an array of slots. These slots must be passed to the `createXStateTreeMachine` function.
|
|
159
159
|
|
|
160
160
|
### Inter-machine communication
|
|
161
161
|
|
|
@@ -182,7 +182,7 @@ That adds two events to the system, a no payload event (`{ type: "BASIC" }`) and
|
|
|
182
182
|
These events can be added anywhere, either next to a component for component specific events or in a module for events that are for multiple machines. One thing that it is important to keep in mind is that these `declare global` declarations must be loaded by the `.d.ts` files when importing the component, otherwise the events will be missing. Which means
|
|
183
183
|
|
|
184
184
|
1. If they are in their own file, say for a module level declaration, that file will need to be imported somewhere. Somewhere that using a component will trigger the import
|
|
185
|
-
2. If they are tied to a component they need to be in the index.ts file that imports the view/selectors/actions etc and calls `
|
|
185
|
+
2. If they are tied to a component they need to be in the index.ts file that imports the view/selectors/actions etc and calls `createXStateTreeMachine`. If they are in the file containing those functions the index.d.ts file will not end up importing them.
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
### [Storybook](https://storybook.js.org)
|
package/lib/testingUtilities.js
CHANGED
|
@@ -77,7 +77,8 @@ export function buildTestRootComponent(machine, logger) {
|
|
|
77
77
|
if (!machine.meta) {
|
|
78
78
|
throw new Error("Root machine has no meta");
|
|
79
79
|
}
|
|
80
|
-
if (!machine.meta.view)
|
|
80
|
+
if ((machine.meta.builderVersion === 1 && !machine.meta.view) ||
|
|
81
|
+
(machine.meta.builderVersion === 2 && !machine.meta.View)) {
|
|
81
82
|
throw new Error("Root machine has no associated view");
|
|
82
83
|
}
|
|
83
84
|
const onChangeEmitter = new TinyEmitter();
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -202,7 +202,7 @@ export declare function buildSelectors<TMachine extends AnyStateMachine, TSelect
|
|
|
202
202
|
*
|
|
203
203
|
* It also delays for 5ms to ensure any React re-rendering happens in response to the state transition
|
|
204
204
|
*/
|
|
205
|
-
export declare function buildTestRootComponent<TMachine extends AnyStateMachine, TSelectors extends AnySelector, TActions extends AnyActions, TContext = ContextFrom<TMachine>>(machine: StateMachine<TContext, XstateTreeMachineStateSchemaV1<TMachine, TSelectors, TActions>, EventFrom<TMachine>>, logger: typeof console.log): {
|
|
205
|
+
export declare function buildTestRootComponent<TMachine extends AnyStateMachine, TSelectors extends AnySelector, TActions extends AnyActions, TContext = ContextFrom<TMachine>>(machine: StateMachine<TContext, XstateTreeMachineStateSchemaV1<TMachine, TSelectors, TActions> | XstateTreeMachineStateSchemaV2<TMachine, TSelectors, TActions>, EventFrom<TMachine>>, logger: typeof console.log): {
|
|
206
206
|
rootComponent: () => JSX.Element | null;
|
|
207
207
|
addTransitionListener: (listener: () => void) => void;
|
|
208
208
|
awaitTransition(): Promise<void>;
|
package/lib/xstateTree.js
CHANGED
|
@@ -35,6 +35,7 @@ export function onBroadcast(handler) {
|
|
|
35
35
|
function cacheKeyForInterpreter(
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
37
|
interpreter) {
|
|
38
|
+
console.log("cacheKeyForInterpreter", interpreter);
|
|
38
39
|
return interpreter.sessionId;
|
|
39
40
|
}
|
|
40
41
|
const getViewForInterpreter = memoize((interpreter) => {
|
|
@@ -54,7 +55,10 @@ const getViewForInterpreter = memoize((interpreter) => {
|
|
|
54
55
|
},
|
|
55
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
57
|
{ serializer: cacheKeyForInterpreter });
|
|
57
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
export const getMultiSlotViewForChildren = memoize((parent, slot) => {
|
|
58
62
|
return React.memo(function MultiSlotView() {
|
|
59
63
|
const [_, children] = useService(parent);
|
|
60
64
|
const interpreters = [...children.values()];
|
|
@@ -64,10 +68,7 @@ const getMultiSlotViewForChildren = memoize((parent, slot) => {
|
|
|
64
68
|
return (React.createElement(XstateTreeMultiSlotView, { childInterpreters: interpretersWeCareAbout }));
|
|
65
69
|
});
|
|
66
70
|
}, {
|
|
67
|
-
|
|
68
|
-
serializer: ((interpreter, slot) =>
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
`${cacheKeyForInterpreter(interpreter)}-${slot}`),
|
|
71
|
+
serializer: (args) => `${cacheKeyForInterpreter(args[0])}-${args[1]}`,
|
|
71
72
|
});
|
|
72
73
|
function useSlots(interpreter, slots) {
|
|
73
74
|
return useConstant(() => {
|
package/package.json
CHANGED