@koordinates/xstate-tree 5.1.0-next.1 → 5.1.0-next.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/README.md +36 -0
- package/lib/xstate-tree.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,6 +185,42 @@ 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
|
+
### Utilities
|
|
189
|
+
|
|
190
|
+
#### `viewToMachine`
|
|
191
|
+
|
|
192
|
+
This utility accepts a React view that does not take any props and wraps it with an xstate-tree machine so you can easily invoke arbitrary React views in your xstate machines
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
function MyView() {
|
|
196
|
+
return <div>My View</div>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const MyViewMachine = viewToMachine(MyView);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### `buildRoutingMachine`
|
|
203
|
+
|
|
204
|
+
This utility aims to reduce boilerplate by generating a common type of state machine, a routing machine. This is a machine that solely consists of routing events that transition to states that invoke xstate-tree machines.
|
|
205
|
+
|
|
206
|
+
The first argument is the array of routes you wish to handle, and the second is an object mapping from those event types to the xstate-tree machine that will be invoked for that routing event
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
const routeA = createRoute.simpleRoute()({
|
|
210
|
+
url: "/a",
|
|
211
|
+
event: "GO_TO_A",
|
|
212
|
+
});
|
|
213
|
+
const routeB = createRoute.simpleRoute()({
|
|
214
|
+
url: "/b",
|
|
215
|
+
event: "GO_TO_B",
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const RoutingMachine = buildRoutingMachine([routeA, routeB], {
|
|
219
|
+
GO_TO_A: MachineA,
|
|
220
|
+
GO_TO_B: MachineB,
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
188
224
|
### Type helpers
|
|
189
225
|
|
|
190
226
|
There are some exported type helpers for use with xstate-tree
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -496,6 +496,13 @@ export declare type RouteMeta<T> = T extends Route<any, any, any, infer TMeta> ?
|
|
|
496
496
|
*/
|
|
497
497
|
export declare type RouteParams<T> = T extends Route<infer TParams, any, any, any> ? TParams : undefined;
|
|
498
498
|
|
|
499
|
+
/**
|
|
500
|
+
* @public
|
|
501
|
+
*
|
|
502
|
+
* Extract query type from route
|
|
503
|
+
*/
|
|
504
|
+
export declare type RouteQuery<T> = T extends Route<any, infer TQuery, any, any> ? TQuery : undefined;
|
|
505
|
+
|
|
499
506
|
declare type RouteRedirect<TParams, TQuery, TMeta> = (args: MakeEmptyObjectPropertiesOptional<{
|
|
500
507
|
params: TParams;
|
|
501
508
|
query: TQuery;
|
package/package.json
CHANGED