@koordinates/xstate-tree 4.1.6 → 4.2.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 +8 -0
- package/lib/xstate-tree.d.ts +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,6 +185,14 @@ These events can be added anywhere, either next to a component for component spe
|
|
|
185
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
|
+
### Type helpers
|
|
189
|
+
|
|
190
|
+
There are some exported type helpers for use with xstate-tree
|
|
191
|
+
|
|
192
|
+
* `SelectorsFrom<TMachine>`: Takes a machine and returns the type of the selectors object
|
|
193
|
+
* `ActionsFrom<TMachine>`: Takes a machine and returns the type of the actions object
|
|
194
|
+
|
|
195
|
+
|
|
188
196
|
### [Storybook](https://storybook.js.org)
|
|
189
197
|
|
|
190
198
|
It is relatively simple to display xstate-tree views directly in Storybook. Since the views are plain React components that accept selectors/actions/slots/inState as props you can just import the view and render it in a Story
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -26,6 +26,17 @@ export declare type Actions<TMachine extends AnyStateMachine, TSelectorsOutput,
|
|
|
26
26
|
selectors: TSelectorsOutput;
|
|
27
27
|
}) => TOut;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*
|
|
32
|
+
* Retrieves the actions return type from the xstate-tree machine
|
|
33
|
+
*/
|
|
34
|
+
export declare type ActionsFrom<TMachine extends AnyXstateTreeMachine> = TMachine extends StateMachine<any, infer TMeta, any> ? TMeta extends {
|
|
35
|
+
meta: {
|
|
36
|
+
actions: infer TOut;
|
|
37
|
+
};
|
|
38
|
+
} ? TOut extends (...args: any) => any ? ReturnType<TOut> : never : never : never;
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* @public
|
|
31
42
|
*/
|
|
@@ -619,6 +630,17 @@ export declare type Selectors<TMachine extends AnyStateMachine, TOut> = (args: {
|
|
|
619
630
|
inState: MatchesFrom<TMachine>;
|
|
620
631
|
}) => TOut;
|
|
621
632
|
|
|
633
|
+
/**
|
|
634
|
+
* @public
|
|
635
|
+
*
|
|
636
|
+
* Retrieves the selector return type from the xstate-tree machine
|
|
637
|
+
*/
|
|
638
|
+
export declare type SelectorsFrom<TMachine extends AnyXstateTreeMachine> = TMachine extends StateMachine<any, infer TMeta, any> ? TMeta extends {
|
|
639
|
+
meta: {
|
|
640
|
+
selectors: infer TOut;
|
|
641
|
+
};
|
|
642
|
+
} ? TOut extends (...args: any) => any ? ReturnType<TOut> : never : never : never;
|
|
643
|
+
|
|
622
644
|
/**
|
|
623
645
|
* @public
|
|
624
646
|
*/
|
package/package.json
CHANGED