XState is a library for creating, interpreting, and executing finite state machines and statecharts.
This library provides helper functions for using XState in Angular applications
A function that interprets the given machine and starts a service that runs for the lifetime of the component in case you provide the XstateAngular service in the component. If you provide the XstateAngular service in the root or in the AppModule, then the service never stops.
options (optional) - Interpreter options OR one of the following Machine Config options: guards, actions, activities, services, delays, immediate, context, or state.
Returns{ state$, send, service }:
state$ - Represents the current state of the machine as an XState State Observable.
send - A function that sends events to the running service.
service - The created service.
useService(service)
A function that subscribes to state changes from an existing service.
state$ - Represents the current state of the service as an XState State Observable.
send - A function that sends events to the running service.
service - The existing service.
You can find an example for how you can use the useService helper function and the Actor model on this example app:
Configuring Machines
Existing machines can be configured by passing the machine options as the 2nd argument of XstateAngular.useMachine(machine, options).
Example: the 'fetchData' service and 'notifySuccess' action are both configurable: