Actor-based state management & orchestration for complex app logic.
#3727 5fb3c68
Thanks @Andarist! - exports
field has been added to the package.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! - The createService(machine)
hook has been removed; use the useActorRef(logic)
hook instead.
#4748 d73ac8e48
Thanks @Andarist! - The fromActorRef(actorRef)
has been added. You can use it to get an accessor for reactive snapshot of any existing actorRef
.
#4748 d73ac8e48
Thanks @Andarist! - The useActor
hook accepts an actor logic
now and not an existing actorRef
. It's used to creating a new instance of an actor and it works just like useMachine
used to work (useMachine
is now just an alias of useActor
).
15b7dd1f0
Thanks @devanfarrell! - Removed this
from machine snapshot methods to fix issues with accessing those methods from union of actors and their snapshots.#4290 7a8796f80
Thanks @davidkpiano! - An error will now be thrown if an incompatible state value is passed to machine.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' });
#4231 c2402e7bc
Thanks @davidkpiano! - The actor
passed to useSelector(actor, selector)
is now allowed to be undefined
for an actor that may not exist yet. For actors that may be undefined
, the snapshot
provided to the selector
function can also be undefined
:
const count = useSelector(maybeActor, (snapshot) => {
// `snapshot` may be undefined
return snapshot?.context.count;
});
count; // number | undefined
#4231 c2402e7bc
Thanks @davidkpiano! - The actor
passed to useSelector(actor, selector)
is now allowed to be undefined
for an actor that may not exist yet. For actors that may be undefined
, the snapshot
provided to the selector
function can also be undefined
:
const count = useSelector(maybeActor, (snapshot) => {
// `snapshot` may be undefined
return snapshot?.context.count;
});
count; // number | undefined
#4731 960cdcbcb
Thanks @davidkpiano! - You can now import getInitialSnapshot(…)
from xstate
directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) without createActor(…)
:
import { getInitialSnapshot } from 'xstate';
import { someMachine } from './someMachine';
// Returns the initial snapshot (state) of the machine
const initialSnapshot = getInitialSnapshot(
someMachine,
{ name: 'Mateusz' } // optional input
);
#4728 659efd5c1
Thanks @Andarist! - Fixed compatibility issue of the internal type definitions with TypeScript 5.0
#4712 2f1d36a9d
Thanks @davidkpiano! - Ensure that InteropObservable
and InteropSubscribable
are present in the type definition file.
#4694 0b6dff210
Thanks @davidkpiano! - Add UnknownMachineConfig
type
#4704 78699aef6
Thanks @Andarist! - createActor
will now error if the required input
is not given to it.
#4688 14902e17a
Thanks @Andarist! - The schemas
property in setup(...)
is now passed through to the resulting machine. This property is meant to be used with future developer tooling, and is typed as unknown
for now.