github statelyai/xstate xstate@5.0.0-beta.45

latest releases: @xstate/svelte@3.0.5, @xstate/vue@3.1.4, @xstate/store@2.6.0...
pre-release10 months ago

Minor Changes

  • #4467 3c71e537d Thanks @Andarist! - The state.configuration property has been renamed to state._nodes.

    - state.configuration
    + state._nodes
  • #4467 3c71e537d Thanks @Andarist! - The state.meta getter has been replaced with state.getMeta() methods:

    - state.meta
    + state.getMeta()
  • #4353 a3a11c84e Thanks @davidkpiano! - You can now use the setup({ ... }).createMachine({ ... }) function to setup implementations for actors, actions, guards, and delays that will be used in the created machine:

    import { setup, createMachine } from 'xstate';
    
    const fetchUser = fromPromise(async ({ input }) => {
      const response = await fetch(`/user/${input.id}`);
      const user = await response.json();
      return user;
    });
    
    const machine = setup({
      actors: {
        fetchUser
      },
      actions: {
        clearUser: assign({ user: undefined })
      },
      guards: {
        isUserAdmin: (_, params) => params.user.role === 'admin'
      }
    }).createMachine({
      // ...
      invoke: {
        // Strongly typed!
        src: 'fetchUser',
        input: ({ context }) => ({ id: context.userId }),
        onDone: {
          guard: {
            type: 'isUserAdmin',
            params: ({ context }) => ({ user: context.user })
          },
          target: 'success',
          actions: assign({ user: ({ event }) => event.output })
        },
        onError: {
          target: 'failure',
          actions: 'clearUser'
        }
      }
    });

Patch Changes

Don't miss a new xstate release

NewReleases is sending notifications on new releases.