Skip to content

xstate@4.20.0

Choose a tag to compare

@github-actions github-actions released this 01 Jun 13:30
· 4135 commits to next since this release
d4b0419

Minor Changes

  • 28059b9f #2197 Thanks @davidkpiano! - All spawned and invoked actors now have a .getSnapshot() method, which allows you to retrieve the latest value emitted from that actor. That value may be undefined if no value has been emitted yet.

    const machine = createMachine({
      context: {
        promiseRef: null
      },
      initial: 'pending',
      states: {
        pending: {
          entry: assign({
            promiseRef: () => spawn(fetch(/* ... */), 'some-promise')
          })
        }
      }
    });
    
    const service = interpret(machine)
      .onTransition(state => {
        // Read promise value synchronously
        const resolvedValue = state.context.promiseRef?.getSnapshot();
        // => undefined (if promise not resolved yet)
        // => { ... } (resolved data)
      })
      .start();
    
    // ...

Patch Changes

  • 4ef03465 #2240 Thanks @VanTanev! - Preserve StateMachine type when .withConfig() and .withContext() modifiers are used on a machine.