Repository navigation
xstate@4.12.0
4.12.0
Minor Changes
b72e29dd#1354 Thanks @davidkpiano! - TheActiontype was simplified, and as a result, you should see better TypeScript performance.
-
4dbabfe7#1320 Thanks @davidkpiano! - Theinvoke.srcproperty now accepts an object that describes the invoke source with itstypeand other related metadata. This can be read from theservicesoption in themeta.srcargument:const machine = createMachine( { initial: 'searching', states: { searching: { invoke: { src: { type: 'search', endpoint: 'example.com' } // ... } // ... } } }, { services: { search: (context, event, { src }) => { console.log(src); // => { endpoint: 'example.com' } } } } );
Specifying a string for
invoke.srcwill continue to work the same; e.g., ifsrc: 'search'was specified, this would be the same assrc: { type: 'search' }.
8662e543#1317 Thanks @Andarist! - AllTTypestatetype parameters default to{ value: any; context: TContext }now and the parametrized type is passed correctly between various types which results in more accurate types involving typestates.
Patch Changes
3ab3f25e#1285 Thanks @Andarist! - Fixed an issue with initial state of invoked machines being read without custom data passed to them which could lead to a crash when evaluating transient transitions for the initial state.
-
a7da1451#1290 Thanks @davidkpiano! - The "Attempted to spawn an Actor [...] outside of a service. This will have no effect." warnings are now silenced for "lazily spawned" actors, which are actors that aren't immediately active until the function that creates them are called:// ⚠️ "active" actor - will warn spawn(somePromise); // 🕐 "lazy" actor - won't warn spawn(() => somePromise); // 🕐 machines are also "lazy" - won't warn spawn(someMachine);
It is recommended that all
spawn(...)-ed actors are lazy, to avoid accidentally initializing them e.g., when readingmachine.initialStateor calculating otherwise pure transitions. In V5, this will be enforced.
c1f3d260#1317 Thanks @Andarist! - Fixed a type returned by araiseaction - it's nowRaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>instead ofRaiseAction<TEvent> | SendAction<TContext, TEvent, TEvent>. This makes it comaptible in a broader range of scenarios.
8270d5a7#1372 Thanks @christianchown! - Narrowed theServiceConfigtype definition to use a specific event type to prevent compilation errors on strictly-typedMachineOptions.
01e3e2dc#1320 Thanks @davidkpiano! - The JSON definition forstateNode.invokeobjects will no longer include theonDoneandonErrortransitions, since those transitions are already merged into thetransitionsarray. This solves the issue of reviving a serialized machine from JSON, where before, theonDoneandonErrortransitions for invocations were wrongly duplicated.