Releases: statelyai/xstate
@xstate/[email protected]
Minor Changes
a473205d
#1699 Thanks @davidkpiano! - The@xstate/inspect
tool now usesfast-safe-stringify
for internal JSON stringification of machines, states, and events when regularJSON.stringify()
fails (e.g., due to circular structures).
[email protected]
[email protected]
Minor Changes
-
6596d0ba
#1622 Thanks @davidkpiano! - Spawned/invoked actors and interpreters are now typed as extendingActorRef
(e.g.,SpawnedActorRef
) rather thanActor
orInterpreter
. This unification of types should make it more straightforward to provide actor types:import { - Actor + ActorRef } from 'xstate'; // ... interface SomeContext { - server?: Actor; + server?: ActorRef<ServerEvent>; }
It's also easier to specify the type of a spawned/invoked machine with
ActorRefFrom
:import { createMachine, - Actor + ActorRefFrom } from 'xstate'; const serverMachine = createMachine<ServerContext, ServerEvent>({ // ... }); interface SomeContext { - server?: Actor; // difficult to type + server?: ActorRefFrom<typeof serverMachine>; }
Patch Changes
@xstate/[email protected]
Minor Changes
-
89f9c27c
#1622 Thanks @davidkpiano! - Spawned/invoked actors and interpreters are now typed as extendingActorRef
rather thanActor
orInterpreter
. This unification of types should make it more straightforward to provide actor types in React:import { ActorRef } from 'xstate'; import { useActor } from '@xstate/react'; const Child: React.FC<{ actorRef: ActorRef<SomeEvent, SomeEmitted> }> = ({ actorRef }) => { // `state` is typed as `SomeEmitted` // `send` can be called with `SomeEvent` values const [state, send] = useActor(actorRef); // . .. };
It's also easier to specify the type of a spawned/invoked machine with
ActorRefFrom
:import { createMachine, ActorRefFrom } from 'xstate'; import { useActor } from '@xstate/react'; const someMachine = createMachine<SomeContext, SomeEvent>({ // ... }); const Child: React.FC<{ someRef: ActorRefFrom<typeof someMachine> }> = ({ someRef }) => { // `state` is typed as `State<SomeContext, SomeEvent>` // `send` can be called with `SomeEvent` values const [state, send] = useActor(someRef); // . .. };
@xstate/[email protected]
Minor Changes
-
111a7d13
#1663 Thanks @davidkpiano! - Options passed into graph functions (e.g.,getShortestPaths(machine, options)
) can now resolve.events
based on thestate
:const countMachine = createMachine({ initial: 'active', context: { count: 0 }, states: { active: { on: { ADD: { actions: assign({ count: (context, event) => { return context.count + event.value; } }) } } } } }); const shortestPaths = getShortestPaths(countMachine, { events: { ADD: state => { // contrived example: if `context.count` is >= 10, increment by 10 return state.context.count >= 10 ? [{ type: 'ADD', value: 10 }] : [{ type: 'ADD', value: 1 }]; } } }); // The keys to the shortest paths will look like: // "active" | { count: 0 } // "active" | { count: 1 } // "active" | { count: 2 } // ... // "active" | { count: 10 } // "active" | { count: 20 } // "active" | { count: 30 }
@xstate/[email protected]
[email protected]
@xstate/[email protected]
[email protected]
Minor Changes
-
119db8fb
#1577 Thanks @davidkpiano! - Expressions can now be used in thestop()
action creator:// ... actions: stop(context => context.someActor);
Patch Changes
-
8c78e120
#1570 Thanks @davidkpiano! - The return type ofspawn(machine)
will now beActor<State<TContext, TEvent>, TEvent>
, which is a supertype ofInterpreter<...>
. -
602687c2
#1566 Thanks @davidkpiano! - Exit actions will now be properly called when an invoked machine reaches its final state. See #1109 for more details. -
6e44d02a
#1553 Thanks @davidkpiano! - Thestate.children
property now properly shows all spawned and invoked actors. See #795 for more details. -
72b0880e
#1504 Thanks @Andarist! - Addedstatus
property on theInterpreter
- this can be used to differentiate not started, running and stopped interpreters. This property is best compared to values on the newInterpreterStatus
export.
@xstate/[email protected]
Patch Changes
-
c7927083
#1516 Thanks @davidkpiano! - Thesend
function returned from theuseService()
now can take two arguments (an event type and payload), to match the behavior of@xstate/react
version 0.x. -
db77623a
#1516 Thanks @davidkpiano! - Thesend
value returned from theuseService()
hook will now accept a payload, which matches the signature of thesend
value returned from theuseMachine()
hook:const [state, send] = useService(someService); // ... // this is OK: send('ADD', { value: 3 }); // which is equivalent to: send({ type: 'ADD', value: 3 });
-
93f6db02
#1594 Thanks @Andarist! - Fixed an issue with internalsetState
inuseService
being called with 2 arguments instead of 1. -
72b0880e
#1504 Thanks @Andarist! - Fixed issue withuseService
returning an initial state for services in their final states.