Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,51 +60,45 @@ Then pass the interpreter instance and a callback function to this module!

```js
const { Machine, interpret } = require("xstate");
const componentTree = require("xstate-component-tree");
const ComponentTree = require("xstate-component-tree");

const statechart = Machine({
// ...
});

const service = interpret(statechart);

componentTree(service, (tree) => {
new ComponentTree(service, (tree) => {
//
});
```

The second argument to the function will be called every time the machine transitions. It will pass the callback a new object representing all the views defined on currently active states, all correctly nested to match the structure of the statechart.

```js
componentTree(service, (tree) => {
new ComponentTree(service, (tree) => {
/**
*
* tree will be something like this
*
* [{
* id: "machine-id",
* children: [{
* component: MyComponent,
* children: [],
* props: false
* }],
* component: MyComponent,
* children: [],
* props: false,
* }]
*
* or if there are nested components
*
* [{
* id: "machine-id",
* children: [{
* component: MyComponent,
* props: false
* children : [{
* component : ChildComponent,
* props: {
* one1 : 1
* },
* children: []
* }]
* }],
* component: MyComponent,
* props: false
* children : [{
* component : ChildComponent,
* props: {
* one1 : 1
* },
* children: []
* }]
* }]
*
*/
Expand Down
Loading