Skip to content

Commit 47abc1e

Browse files
committed
feat: xstate v5 support
1 parent ff80874 commit 47abc1e

21 files changed

+323
-272
lines changed

.changeset/purple-emus-stare.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"xstate-component-tree": major
3+
---
4+
5+
# 🎉 xstate v5 support 🎉
6+
7+
This release finally updates `xstate-component-tree` to work with modern versions of xstate. No major API changes within the library itself, mostly v4 to v5 stuff like [always sending `{ type : "EVENT" }`](https://stately.ai/docs/migration#actorsend-no-longer-accepts-string-types).

.vscode/launch.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"type": "pwa-node",
8+
"name": "uvu All",
9+
"type": "node",
910
"request": "launch",
10-
"name": "Run uvu",
11-
"console": "integratedTerminal",
1211
"skipFiles": [
1312
"<node_internals>/**"
1413
],
15-
"program": "${workspaceFolder}/node_modules/uvu/bin.js",
16-
"args": ["tests"],
17-
},
18-
{
19-
"type": "pwa-node",
20-
"request": "launch",
21-
"name": "Run uvu (current file)",
22-
"console": "integratedTerminal",
23-
"skipFiles": [
24-
"<node_internals>/**"
14+
"program": "${workspaceFolder}/node_modules/.bin/uvu",
15+
"args": [
16+
"tests",
17+
"\\.test\\.js$"
2518
],
26-
"program": "${workspaceFolder}/node_modules/uvu/bin.js",
27-
"args": ["tests", "${fileBasenameNoExtension}"]
28-
}
19+
"console": "integratedTerminal",
20+
"windows": {
21+
"program": "${workspaceFolder}/node_modules/uvu/bin.js"
22+
}
23+
},
2924
]
3025
}

examples/svelte/src/App.svelte

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1+
<script>
2+
import { ComponentTree } from "xstate-component-tree";
3+
4+
import service from "./statechart.js";
5+
6+
import Children from "./children.svelte";
7+
8+
let components = [];
9+
10+
new ComponentTree(service, (tree) => {
11+
components = tree;
12+
});
13+
14+
service.start();
15+
</script>
16+
117
<div>
218
<p>LAYOUT RENDERED AT {Date.now()}</p>
319

420
<code>{JSON.stringify($service.value)}</code>
521

622
<p>
7-
<button on:click={() => service.send("NAV")}>Navigate</button>
23+
<button on:click={() => service.send({ type: "NAV" })}>Navigate</button>
824
</p>
925

1026
<Children children={components} />
1127
</div>
12-
13-
<script>
14-
import ComponentTree from "xstate-component-tree";
15-
16-
import service from "./statechart.js";
17-
18-
import Children from "./children.svelte";
19-
20-
let components = [];
21-
22-
new ComponentTree(service, (tree) => {
23-
components = tree;
24-
});
25-
26-
service.start();
27-
</script>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
<script>
2+
import service from "./statechart.js";
3+
</script>
4+
15
<p>
2-
<button on:click={() => service.send("NEXT")}>Next Child</button>
6+
<button on:click={() => service.send({ type: "NEXT" })}>Next Child</button>
37
</p>
4-
5-
<script>
6-
import service from "./statechart.js";
7-
</script>

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"strip-ansi": "^7.0.1",
5959
"typescript": "^5.0.3",
6060
"uvu": "^0.5.4",
61-
"xstate": "^4.37.0"
61+
"xstate": "^5.19.0"
6262
},
6363
"peerDependencies": {
6464
"xstate": "^4.7.8"

src/component-helper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param {StateNode} node - Xstate node data
1010
* @returns {StateNode} an xstate node containing component information in its meta
1111
*/
12-
export default (child, node = {}) => {
12+
const componentHelper = (child, node = {}) => {
1313
/**
1414
* Handle both bare component & { component, props } via destructuring & default values
1515
* 1. state : component(UIComponent, {})
@@ -38,3 +38,7 @@ export default (child, node = {}) => {
3838

3939
return node;
4040
};
41+
42+
export {
43+
componentHelper,
44+
};

0 commit comments

Comments
 (0)