@koordinates/xstate-tree 5.1.0-next.1 → 5.1.0-next.2

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.
Files changed (2) hide show
  1. package/README.md +36 -0
  2. 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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "5.1.0-next.1",
5
+ "version": "5.1.0-next.2",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [