Conversation
🦋 Changeset detectedLatest commit: 2788fb2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
|
I am quite interested in this for binding the route with machine state actors. Now that This would facilitate keeping the route in sync with the active state. Happy to provide more context if needed. |
|
@christophe-g Glad you're interested in it! Emitting events should be explicit, though, and it may be better to More context would be appreciated. |
@davidkpiano - this is not really more context, but a new lit controller binding xstate actor machine with a router.
I took your advice for this controller ... Any change to have this PR merged ? |
|
Dear @davidkpiano - just interested to know if this PR has any chance to be merged, or if there are any blocking issues ? I have build a lit-controller around this (see above). This PR allows to de-couple business logic (handled by xstate machine), routing / navigation (natively handled by the browser), and views (provided by the router / also bound to state machine), which is great! |
It does have a chance! Going to update it soon. |
@davidkpiano - Fantastic, thank you ! |
|
For anyone that needs this, I've implemented a verbose workaround:
Then you can route to a specific state by assigning Routable state would simplify things massively though. const todoMachine = createMachine({
type: 'parallel',
states: {
todo: {
initial: 'new',
states: {
new: {},
editing: {}
}
},
filter: {
initial: 'all',
states: {
all: {
route: { id: "filterRoute" }
},
active: {
route: { id: "filterRoute" }
},
completed: {
route: [{ id: "filterRoute" }, {id: "helloWorld"}]
},
hello: {
route: { id: "helloWorld" }
},
world: {
route: { id: "helloWorld" }
}
}
}
}
}); |
Routable states are a hidden gem of xstate. Using with a lot of joy for instance in relatively complex stepper UI, allowing to bind the view with the state through the route. |
|
I'd love to see this as part of xstates core. still plans to merge this in @davidkpiano? |
|
This would be a huge help in keeping browser routing in sync with state machines! Thankful for your hard work @davidkpiano! Hope to see this available in V5 soon! |
Yes, I'd still like to see this merged in soon |
|
🙏🏼 What faith must I convert to for my plea to realise? 🥺 @davidkpiano |
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
…lated tests and type definitions
Added routable states. States with
route: {}and an explicitidcan be navigated to from anywhere via a single{ type: 'xstate.route', to: id }event.Routes support guards for conditional navigation: