github statelyai/xstate xstate@5.31.0

5 hours ago

Minor Changes

  • #5429 9d9c1fe Thanks @davidkpiano! - Add mapState(snapshot, mapper) to map a snapshot to values based on active state(s).

    import { mapState } from 'xstate';
    
    const results = mapState(snapshot, {
      states: {
        loading: { map: () => 'Loading...' },
        success: { map: (snap) => snap.context.data },
        error: { map: (snap) => snap.context.error.message }
      }
    });
    
    console.log(results);
    // E.g. if snapshot.value === 'loading', then:
    // [
    //   { stateNode: { key: 'loading' }, result: 'Loading...' }
    // ]
  • #5430 e543599 Thanks @davidkpiano! - Add maxIterations option to configure the maximum number of microsteps allowed before throwing an infinite loop error. The default is Infinity (no limit) to avoid breaking existing machines.

    You can configure it when creating a machine:

    const machine = createMachine({
      // ... machine config
      options: {
        maxIterations: 1000 // set a limit to enable infinite loop detection
      }
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.