@xstate/angular? #3205
Replies: 15 comments 35 replies
-
Here's a sample repository I found to give an overview of what using XState in Angular can look like. |
Beta Was this translation helpful? Give feedback.
-
I don't think that any of us have enough experience with Angular to know that ecosystem's conventions. We would be open to publishing a package like this - but it would be best if the community member could create it in this repo. |
Beta Was this translation helpful? Give feedback.
-
I've got some code that I never quite got working how I wanted. But basically I made useMachine, useInterpret, useSelector, and useActor functions that return RxJS observables. I also have a StateMachineServiceBase class that wraps the useMachine function, making it easily extendable by an Angular service. But I think it's missing something, something to make it that last bit easy to get either a global or scoped Angular service that automatically stops the XState interpretor in the OnDestroy lifecycle hook. I'll upload it to GitHub and link it in case you want to peek at it. |
Beta Was this translation helpful? Give feedback.
-
I'd also like to posit a small Angular-ism in naming machine files/folders (just for @xstate/angular users). Angular folks are used to certain file/folder naming/structure conventions. The point I feel most strongly about is a file naming convention like this: Additionally, because the VS Code typegen gives us an extra file, the machine file should be in a folder named after the machine, optionally nested in a machines folder if there are multiple machines where you're placing them. Example:
|
Beta Was this translation helpful? Give feedback.
-
In our company xstate is replacing not a structured state management beyond Angular using Rx itself. The easiest way so far has been vanilla services, in many cases exposing Observables and methods to change that state. Therefore we are testing approaches like injecting the machine interpreted as the service itself (without Injectable class wrapper), and putting the responsibility of navigation on some global app state machine. About this approach, the child machine actor sometimes is spawned by the parent machine, but we have a lot of machines scoped to a single component, sending messages to another machines injected in the component and not handled the communication between them by xstate internally. |
Beta Was this translation helpful? Give feedback.
-
Hello guys, another Angular developer here, 4 years of working with Angular and loving it! But i'm new XState and want to use it with Angular. what i want to know is: is there someone who are working to a solution and want some help? is there a repo or something? i fall in love with XState and want to try it right now 😄 |
Beta Was this translation helpful? Give feedback.
-
Same I can’t wait to try xstate with Angular
Sent from Yahoo Mail for iPhone
On Sunday, June 19, 2022, 2:42 PM, David Khourshid ***@***.***> wrote:
Yes, we've had an initial discussion with @keithernet on how to do this, so we're getting somewhere! Will keep everyone updated as we make progress.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I had a discussion with David and then went on vacation for a week so it may take me a little to get back up to speed, but using XState in angular is totally possible right now and, in fact, works well without any additional adapter library. There's a channel in the Stately Discord where I, and other members of the community, are happy to help. |
Beta Was this translation helpful? Give feedback.
-
If you're reading this, it can't hurt to upvote this. https://statelyai.canny.io/xstate/p/xstate-angular |
Beta Was this translation helpful? Give feedback.
-
Are there any updates on the Angular support? Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
-
We have been waiting for some kind soul to address the blatant lack of any comprehensive Angular Examples integrating XState, especially using Angular's excellent Service architecture and Observables. Its 2023 and there seems to be still no movement on this apart from a scattered collection of custom implementations, most of which throw errors, or don't appear to follow XState conventions at all. Personally. I'm struggling to produce more than a hack to include a state machine into Angular, nothing of note and certainly not production ready. Now there is a huge project on the horizon and we are tied into Angular, but can offload a huge task requirements with XState. Unfortunately the past initial days have been trying to come up with a secure and prod-ready implementation for XState into the NG ecosystem. XState is fantastic, its such a shame that Angular developers are still left hanging |
Beta Was this translation helpful? Give feedback.
-
I don't quite follow. How would I do what? The Traffic light example is a widely used example of state control. In fact there are numerous XState examples on it. It's not a problem on doing the Traffic light problem it's a matter of no examples on how to implement the same pattern in Angular, Without any state control it's a rudimentary switch or similar, it would be nonsensical to create such an app now., as a mere elucidation of my core point. The core point being that , there is no comprehensive guide on any practices (best or not) on how to integrate XState into Angular. There is are reims of info on React, and even Svelte (which has barely left the starting post), but non on Angular which is well past entrenched now. Our current project is huge and will involve a substantial state management system, but as I mentioned we are tied to Angular. So for now, it looks like we are going to have to build a custom integration for XState, I wasn't intending to get sidetracked into filling those missing areas in in XState, no matter how interesting that may be (and it would) The Traffic light example I pulled from memory as it is clear and simple and commands no bloated approach to state management, though it could be anything even a simple Toggle button via Observers / Subjects in Angular. The fundamental issue being how to correctly read from the state machine, and fire events to update via Angular's Rxjs implementation or similar. No need to understand the creation of the machine itself, that is particularly easy as your Documentation is excellent. |
Beta Was this translation helpful? Give feedback.
-
Can you start by showing how you would do this without XState, and we can take that code and translate it to an XState example?
After this David, Would you please add the solution to xState Doc, So We can practice, also on YouTube channel will be fine too.
Thank you.
Sent from Yahoo Mail for iPhone
On Tuesday, January 24, 2023, 5:39 AM, David Khourshid ***@***.***> wrote:
Im approaching this merely as a Developer / User. I would like to see a very simple example (such as the Traffic light example) in Angular. Not with custom hacks and such but showing how to get and read the state in an Angular Service, via Rxjs or not, there need be no async calls, or anything.
Can you start by showing how you would do this without XState, and we can take that code and translate it to an XState example?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Just jumping in this conversation. I was thinking of giving an angular implementation for xstate a try. I think this would be a valuable enhancement to the angular ecosystem. If there is any documentation around conventions for third party libraries, that would be very helpful |
Beta Was this translation helpful? Give feedback.
-
Hi all. I was an early adopter of AngularJS, and have used Angular since. I want to see this exist and would like to help. Angular uses decorators to add symbols to prototypes, which are interacted with at runtime. Compositionally, changing xstate dx to declare xstate/machine behaviors on TS classes would seem like the right approach to me. Here's a sketch of how something like this could take shape:
This is class-based, but I'd think the core logic in the decorators could be re-used for functional implementations. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Kicking off a discussion about what an @xstate/angular package would look like. My initial questions revolve around the patterns that a "blessed" library should encourage or discourage? Is it possible to build a class or a helper that makes it as simple as
@xstate/React
's useMachine function to integrate a machine with a component?Beta Was this translation helpful? Give feedback.
All reactions