Skip to content

Commit

Permalink
feat: xstate v5 support
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump xstate from 4.38.3 to 5.19.0

Bumps [xstate](https://github.com/statelyai/xstate) from 4.38.3 to 5.19.0.
- [Release notes](https://github.com/statelyai/xstate/releases)
- [Commits](https://github.com/statelyai/xstate/compare/[email protected]@5.19.0)

---
updated-dependencies:
- dependency-name: xstate
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* refactor: some tests passing

* refactor: tests passing

Few minor hiccups, but I think they're in the test harness and how it's not _actually_ waiting for runs to complete correctly?

* refactor: coverage

* refactor: early-out of repeat runs

TODO: Causing some tests to freak out, but only two

* test: Removed some nonsense

* test: fixed up exploding test

* test: remove .only

* chore: remove gunk

* docs: changeset

* chore: remove gunk

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pat Cavit <[email protected]>
  • Loading branch information
dependabot[bot] and tivac authored Dec 31, 2024
1 parent ff80874 commit e711a23
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 272 deletions.
7 changes: 7 additions & 0 deletions .changeset/purple-emus-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"xstate-component-tree": major
---

# 🎉 xstate v5 support 🎉

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).
27 changes: 11 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"name": "uvu All",
"type": "node",
"request": "launch",
"name": "Run uvu",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/node_modules/uvu/bin.js",
"args": ["tests"],
},
{
"type": "pwa-node",
"request": "launch",
"name": "Run uvu (current file)",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
"program": "${workspaceFolder}/node_modules/.bin/uvu",
"args": [
"tests",
"\\.test\\.js$"
],
"program": "${workspaceFolder}/node_modules/uvu/bin.js",
"args": ["tests", "${fileBasenameNoExtension}"]
}
"console": "integratedTerminal",
"windows": {
"program": "${workspaceFolder}/node_modules/uvu/bin.js"
}
},
]
}
34 changes: 17 additions & 17 deletions examples/svelte/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<script>
import { ComponentTree } from "xstate-component-tree";
import service from "./statechart.js";
import Children from "./children.svelte";
let components = [];
new ComponentTree(service, (tree) => {
components = tree;
});
service.start();
</script>

<div>
<p>LAYOUT RENDERED AT {Date.now()}</p>

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

<p>
<button on:click={() => service.send("NAV")}>Navigate</button>
<button on:click={() => service.send({ type: "NAV" })}>Navigate</button>
</p>

<Children children={components} />
</div>

<script>
import ComponentTree from "xstate-component-tree";
import service from "./statechart.js";
import Children from "./children.svelte";
let components = [];
new ComponentTree(service, (tree) => {
components = tree;
});
service.start();
</script>
10 changes: 5 additions & 5 deletions examples/svelte/src/next-child.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import service from "./statechart.js";
</script>

<p>
<button on:click={() => service.send("NEXT")}>Next Child</button>
<button on:click={() => service.send({ type: "NEXT" })}>Next Child</button>
</p>

<script>
import service from "./statechart.js";
</script>
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"strip-ansi": "^7.0.1",
"typescript": "^5.0.3",
"uvu": "^0.5.4",
"xstate": "^4.37.0"
"xstate": "^5.19.0"
},
"peerDependencies": {
"xstate": "^4.7.8"
Expand Down
6 changes: 5 additions & 1 deletion src/component-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @param {StateNode} node - Xstate node data
* @returns {StateNode} an xstate node containing component information in its meta
*/
export default (child, node = {}) => {
const componentHelper = (child, node = {}) => {
/**
* Handle both bare component & { component, props } via destructuring & default values
* 1. state : component(UIComponent, {})
Expand Down Expand Up @@ -38,3 +38,7 @@ export default (child, node = {}) => {

return node;
};

export {
componentHelper,
};
Loading

0 comments on commit e711a23

Please sign in to comment.