github statelyai/xstate xstate@4.24.0

latest releases: @xstate/svelte@3.0.5, @xstate/vue@3.1.4, @xstate/store@2.6.0...
3 years ago

Minor Changes

  • #2546 a4cfce18c Thanks @davidkpiano! - You can now know if an event will cause a state change by using the new state.can(event) method, which will return true if an interpreted machine will "change" the state when sent the event, or false otherwise:

    const machine = createMachine({
      initial: 'inactive',
      states: {
        inactive: {
          on: {
            TOGGLE: 'active'
          }
        },
        active: {
          on: {
            DO_SOMETHING: { actions: ['something'] }
          }
        }
      }
    });
    
    const state = machine.initialState;
    
    state.can('TOGGLE'); // true
    state.can('DO_SOMETHING'); // false
    
    // Also takes in full event objects:
    state.can({
      type: 'DO_SOMETHING',
      data: 42
    }); // false

    A state is considered "changed" if any of the following are true:

    • its state.value changes
    • there are new state.actions to be executed
    • its state.context changes

    See state.changed (documentation) for more details.

Patch Changes

  • #2632 f8cf5dfe0 Thanks @davidkpiano! - A regression was fixed where actions were being typed as never if events were specified in createModel(...) but not actions:

    const model = createModel(
      {},
      {
        events: {}
      }
    );
    
    model.createMachine({
      // These actions will cause TS to not compile
      entry: 'someAction',
      exit: { type: 'someObjectAction' }
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.