You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Documenting new features
- Rearranging tests a bit to take advantage of new features
BREAKING CHANGE: previously the second arg to the callback function had a single `data` property on it representing the last `State` object seen by the top-level machine. Now it has `state` (same as data was previously), and some bound APIs for interacting with the statechart: `.hasTag()`, `.broadcast()`, and `.matches()`. These are the same APIs available on the `ComponentTree` instance but made available through the callback args for convenience.
Copy file name to clipboardExpand all lines: README.md
+42-4Lines changed: 42 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,7 @@ Machine({
41
41
},
42
42
});
43
43
```
44
+
44
45
Props for the components are also supported via the `props` key.
45
46
46
47
```js
@@ -108,7 +109,7 @@ new ComponentTree(service, (tree) => {
108
109
});
109
110
```
110
111
111
-
This data structure can also contain components from any child statecharts you created using `invoke`, they will be correctly walked & monitored for transitions.
112
+
This data structure can also contain components from any child statecharts you created using `invoke`, they will be correctly walked & monitored for transitions and appear in their expected position within the hierarchy. This lets you compose a larger statechart from several smaller ones and still have them all contribute components to the app.
112
113
113
114
## Advanced Usage
114
115
@@ -208,24 +209,61 @@ import { component } from "xstate-component-tree/component";
-`interpreter`, and instance of a xstate interpreter
214
217
-`callback`, a function that will be executed each time a new tree of components is ready
215
218
-`options`, an optional object containing [configuration values](#options) for the library.
216
219
220
+
The `callback` functions receives two arguments, the first is your assembled tree of components & props. The second is an object with some useful information on it:
221
+
222
+
-`.state`, the returned xstate `State` object for the root machine
223
+
-`.matches()`, a bound version of the [`.matches()` API documented below](#matchesstatename)
224
+
-`.hasTag()`, a bound version of the [`.hasTag()` API documented below](#hastagtag)
225
+
-`.broadcast()`, a bound version of the [`.broadcast()` API documented below](#broadcasteventname--eventobject-payload)
226
+
217
227
#### `options`
218
228
219
229
-`cache` (default `true`), a boolean determining whether or not the value of `load()` functions should be cached. This can be overriden by setting `meta.cache` on any state in the tree where caching needs to be disabled.
220
230
221
231
-`stable` (default: `false`), tells the library to sort states alphabetically before walking them at each tier to help ensure that the component output is more consistent between state transitions.
222
232
223
-
### `component(Component | () => {}, [node])`
233
+
-`verbose` (default: `false`), logs out info about the internal workings & decisions.
Calls the xstate `.send()` method on every running interpreter in the hierarchy. This is especially useful to avoid the use of the `autoforward` option on all of your invoked child machines.
240
+
241
+
-`eventName` is a string event to be sent
242
+
-`eventObject` is an object with a `type` property of the event name, along with other optional fields
243
+
-`payload` is an object of optional fields to be added to the event object
244
+
245
+
#### `.matches(stateName)`
246
+
247
+
-`stateName` is a full or partial state value specified as a string
248
+
249
+
Calls the [xstate `.matches()` method](https://xstate.js.org/docs/guides/states.html#state-matches-parentstatevalue) against all the running machines and returns the result, stopping at the first successful match.
250
+
251
+
#### `.hasTag(tag)`
252
+
253
+
-`tag` is a string, which can be defined on states using the `tags` property
254
+
255
+
Calls the [xstate `.hasTag()` method](https://xstate.js.org/docs/guides/states.html#state-hastag-tag) against all the running machines and returns the result, stopping at the first successful match.
256
+
257
+
### `component()` helper
258
+
259
+
The `component` helper returns an `xstate` node as an object literal, it is solely a convenience method for statechart authors.
260
+
261
+
#### `component(Component | () => {}, [node])`
224
262
225
263
-`Component` is either a component or an arrow function that will be executed. It supports functions that return either a component or a `Promise`.
226
264
-`node` is a valid xstate node, the `meta` object will be created and mixed-in by the `component()`.
0 commit comments