github statelyai/xstate xstate@4.20.1

2 years ago

Patch Changes

  • 99bc5fb9 #2275 Thanks @davidkpiano! - The SpawnedActorRef TypeScript interface has been deprecated in favor of a unified ActorRef 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 in createMachine<typeof someModel>(...), TypeScript will no longer compile machines that are missing the context 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 for InvokeCallback have been improved for better event constraints when using the sendBack 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! - The state.meta value is now calculated directly from state.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'
      //   }
      // }
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.