github statelyai/xstate xstate@5.24.0

one day ago

Minor Changes

  • #5371 b8ec3b1 Thanks @davidkpiano! - Add setup.extend() method to incrementally extend machine setup configurations with additional actions, guards, and delays. This enables composable and reusable machine setups where extended actions, guards, and delays can reference base actions, guards, and delays and support chaining multiple extensions:

    import { setup, not, and } from 'xstate';
    
    const baseSetup = setup({
      guards: {
        isAuthenticated: () => true,
        hasPermission: () => false
      }
    });
    
    const extendedSetup = baseSetup.extend({
      guards: {
        // Type-safe guard references
        isUnauthenticated: not('isAuthenticated'),
        canAccess: and(['isAuthenticated', 'hasPermission'])
      }
    });
    
    // Both base and extended guards are available
    extendedSetup.createMachine({
      on: {
        LOGIN: {
          guard: 'isAuthenticated',
          target: 'authenticated'
        },
        LOGOUT: {
          guard: 'isUnauthenticated',
          target: 'unauthenticated'
        }
      }
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.