-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v5] Routable states #4184
base: main
Are you sure you want to change the base?
[v5] Routable states #4184
Conversation
|
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 ! |
What's the current state? 👍🏼 Would love to see this ! 🚀 |
I see that this PR was marked as ready for review, but this might have gone unnoticed ; ) Just adding a comment here to try revive this powerful feature - and thanks anyway for this great piece of code ! |
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. |
This PR enables developers to mark states as "routes" by providing a
route
config, which is just a normal transition config without the target:The motivation for this is that there are many use-cases for wanting to transition directly to a state, such as in modeling page routes or steps in a multi-step form. Previously, you needed to manually hard-code transitions for these, which resulted in an unnatural and verbose state machine definition.