github statelyai/xstate xstate@4.11.0

3 years ago

Minor Changes

  • 36ed8d0a #1262 Thanks @Andarist! - Improved type inference for InvokeConfig['data']. This has required renaming data property on StateNode instances to doneData. This property was never meant to be a part of the public API, so we don't consider this to be a breaking change.

  • 2c75ab82 #1219 Thanks @davidkpiano! - The resolved value of the invoke.data property is now available in the "invoke meta" object, which is passed as the 3rd argument to the service creator in options.services. This will work for all types of invoked services now, including promises, observables, and callbacks.

    const machine = createMachine({
      initial: 'pending',
      context: {
        id: 42
      },
      states: {
        pending: {
          invoke: {
            src: 'fetchUser',
            data: {
              userId: (context) => context.id
            },
            onDone: 'success'
          }
        },
        success: {
          type: 'final'
        }
      }
    },
    {
      services: {
        fetchUser: (ctx, _, { data }) => {
          return fetch(`some/api/user/${data.userId}`)
            .then(response => response.json());
        }
      }
    }
  • a6c78ae9 #1249 Thanks @davidkpiano! - New property introduced for eventless (transient) transitions: always, which indicates a transition that is always taken when in that state. Empty string transition configs for transient transitions are deprecated in favor of always:

    // ...
    states: {
      playing: {
    +   always: [
    +     { target: 'win', cond: 'didPlayerWin' },
    +     { target: 'lose', cond: 'didPlayerLose' },
    +   ],
        on: {
          // ⚠️ Deprecation warning
    -     '': [
    -       { target: 'win', cond: 'didPlayerWin' },
    -       { target: 'lose', cond: 'didPlayerLose' },
    -     ]
        }
      }
    }
    // ...

    The old empty string syntax ('': ...) will continue to work until V5.

Patch Changes

  • 36ed8d0a #1262 Thanks @Andarist! - StateMachine<any, any, any> is no longer a part of the InvokeConfig type, but rather it creates a union with InvokeConfig in places where it is needed. This change shouldn't affect consumers' code.

Don't miss a new xstate release

NewReleases is sending notifications on new releases.