Patch Changes
-
99bc5fb9
#2275 Thanks @davidkpiano! - TheSpawnedActorRef
TypeScript interface has been deprecated in favor of a unifiedActorRef
interface, which contains the following:interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> { send: (event: TEvent) => void; id: string; subscribe(observer: Observer<T>): Subscription; subscribe( next: (value: T) => void, error?: (error: any) => void, complete?: () => void ): Subscription; getSnapshot: () => TEmitted | undefined; }
For simpler actor-ref-like objects, the
BaseActorRef<TEvent>
interface has been introduced.interface BaseActorRef<TEvent extends EventObject> { send: (event: TEvent) => void; }
-
38e6a5e9
#2334 Thanks @davidkpiano! - When using a model type increateMachine<typeof someModel>(...)
, TypeScript will no longer compile machines that are missing thecontext
property in the machine configuration:const machine = createMachine<typeof someModel>({ // missing context - will give a TS error! // context: someModel.initialContext, initial: 'somewhere', states: { somewhere: {} } });
-
5f790ba5
#2320 Thanks @davidkpiano! - The typing forInvokeCallback
have been improved for better event constraints when using thesendBack
parameter of invoked callbacks:invoke: () => (sendBack, receive) => { // Will now be constrained to events that the parent machine can receive sendBack({ type: 'SOME_EVENT' }); };
-
2de3ec3e
#2272 Thanks @davidkpiano! - Thestate.meta
value is now calculated directly fromstate.configuration
. This is most useful when starting a service from a persisted state:const machine = createMachine({ id: 'test', initial: 'first', states: { first: { meta: { name: 'first state' } }, second: { meta: { name: 'second state' } } } }); const service = interpret(machine); service.start('second'); // `meta` will be computed // the state will have // meta: { // 'test.second': { // name: 'second state' // } // } });