Releases: statelyai/xstate
@xstate/[email protected]
Minor Changes
-
#3727
5fb3c68
Thanks @Andarist! -exports
field has been added to thepackage.json
manifest. It limits what files can be imported from a package - it's no longer possible to import from files that are not considered to be a part of the public API. -
#4265
1153b3f
Thanks @davidkpiano! - FSM-related functions have been removed. -
#4748
d73ac8e48
Thanks @Andarist! - ThecreateService(machine)
hook has been removed; use theuseActorRef(logic)
hook instead. -
#4748
d73ac8e48
Thanks @Andarist! - ThefromActorRef(actorRef)
has been added. You can use it to get an accessor for reactive snapshot of any existingactorRef
. -
#4748
d73ac8e48
Thanks @Andarist! - TheuseActor
hook accepts an actorlogic
now and not an existingactorRef
. It's used to creating a new instance of an actor and it works just likeuseMachine
used to work (useMachine
is now just an alias ofuseActor
).
[email protected]
Patch Changes
- #4739
15b7dd1f0
Thanks @devanfarrell! - Removedthis
from machine snapshot methods to fix issues with accessing those methods from union of actors and their snapshots.
[email protected]
Minor Changes
-
#4290
7a8796f80
Thanks @davidkpiano! - An error will now be thrown if an incompatible state value is passed tomachine.resolveState({ value })
. -
#4693
11b6a1ae1
Thanks @davidkpiano! - You can now inspect microsteps (@xstate.microstep
) and actions (@xstate.action
):const machine = createMachine({ initial: 'a', states: { a: { on: { event: 'b' } }, b: { entry: 'someAction', always: 'c' }, c: {} } }); const actor = createActor(machine, { inspect: (inspEvent) => { if (inspEvent.type === '@xstate.microstep') { console.log(inspEvent.snapshot); // logs: // { value: 'a', … } // { value: 'b', … } // { value: 'c', … } console.log(inspEvent.event); // logs: // { type: 'event', … } } else if (inspEvent.type === '@xstate.action') { console.log(inspEvent.action); // logs: // { type: 'someAction', … } } } }); actor.start(); actor.send({ type: 'event' });
@xstate/[email protected]
Minor Changes
-
#4231
c2402e7bc
Thanks @davidkpiano! - Theactor
passed touseSelector(actor, selector)
is now allowed to beundefined
for an actor that may not exist yet. For actors that may beundefined
, thesnapshot
provided to theselector
function can also beundefined
:const count = useSelector(maybeActor, (snapshot) => { // `snapshot` may be undefined return snapshot?.context.count; }); count; // number | undefined
@xstate/[email protected]
Minor Changes
-
#4231
c2402e7bc
Thanks @davidkpiano! - Theactor
passed touseSelector(actor, selector)
is now allowed to beundefined
for an actor that may not exist yet. For actors that may beundefined
, thesnapshot
provided to theselector
function can also beundefined
:const count = useSelector(maybeActor, (snapshot) => { // `snapshot` may be undefined return snapshot?.context.count; }); count; // number | undefined
[email protected]
Patch Changes
-
#4731
960cdcbcb
Thanks @davidkpiano! - You can now importgetInitialSnapshot(…)
fromxstate
directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) withoutcreateActor(…)
:import { getInitialSnapshot } from 'xstate'; import { someMachine } from './someMachine'; // Returns the initial snapshot (state) of the machine const initialSnapshot = getInitialSnapshot( someMachine, { name: 'Mateusz' } // optional input );
[email protected]
Patch Changes
-
#4728
659efd5c1
Thanks @Andarist! - Fixed compatibility issue of the internal type definitions with TypeScript 5.0 -
#4712
2f1d36a9d
Thanks @davidkpiano! - Ensure thatInteropObservable
andInteropSubscribable
are present in the type definition file. -
#4694
0b6dff210
Thanks @davidkpiano! - AddUnknownMachineConfig
type
[email protected]
Minor Changes
-
#4704
78699aef6
Thanks @Andarist! -createActor
will now error if the requiredinput
is not given to it. -
#4688
14902e17a
Thanks @Andarist! - Theschemas
property insetup(...)
is now passed through to the resulting machine. This property is meant to be used with future developer tooling, and is typed asunknown
for now.
Patch Changes
[email protected]
Patch Changes
-
#4685
e43eab144
Thanks @davidkpiano! - State IDs that have periods in them are now supported if those periods are escaped.The motivation is that external tools, such as Stately Studio, may allow users to enter any text into the state ID field. This change allows those tools to escape periods in state IDs, so that they don't conflict with the internal path-based state IDs.
E.g. if a state ID of
"Loading..."
is entered into the state ID field, instead of crashing either the external tool and/or the XState state machine, it should be converted by the tool to"Loading\\.\\.\\."
, and those periods will be ignored by XState.
@xstate/[email protected]
Patch Changes
-
#4695
52900a084
Thanks @davidkpiano! - Options increateActorContext
are now properly merged with provider options. Previously, provider options replaced the actor options.const { inspect } = createBrowserInspector(); const SomeContext = createActorContext(someMachine, { inspect }); // ... // Options are now merged: // { inspect: inspect, input: 10 } <SomeContext.Provider options={{ input: 10 }}> {/* ... */} </SomeContext.Provider>;