xstate

Actor-based state management & orchestration for complex app logic.

MIT License

Downloads
14.3M
Stars
26.2K
Committers
362

Bot releases are visible (Hide)

xstate - [email protected]

Published by github-actions[bot] about 1 year ago

Major Changes

  • #4036 e2440f0b1 Thanks @davidkpiano! - Actor types can now be specified in the .types property of createMachine:

    const fetcher = fromPromise(() => fetchUser());
    
    const machine = createMachine({
      types: {} as {
        actors: {
          src: 'fetchData'; // src name (inline behaviors ideally inferred)
          id: 'fetch1' | 'fetch2'; // possible ids (optional)
          logic: typeof fetcher;
        };
      },
      invoke: {
        src: 'fetchData', // strongly typed
        id: 'fetch2', // strongly typed
        onDone: {
          actions: ({ event }) => {
            event.output; // strongly typed as { result: string }
          }
        },
        input: { foo: 'hello' } // strongly typed
      }
    });
    

Minor Changes

  • #4157 31eb5f8a1 Thanks @Valkendorm! - Merge sendBack and receive with other properties of fromCallback logic creator.

    const callbackLogic = fromCallback(({ input, system, self, sendBack, receive }) => { ... });
    
xstate - [email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

  • #4159 8bfbb8531 Thanks @Andarist! - The cancel action was added to the main export:

    import { cancel } from 'xstate';
    
xstate - [email protected]

Published by github-actions[bot] about 1 year ago

Major Changes

  • #4049 afc690046 Thanks @davidkpiano! - If context types are specified in the machine config, the context property will now be required:

    // ❌ TS error
    createMachine({
      types: {} as {
        context: { count: number };
      }
      // Missing context property
    });
    
    // ✅ OK
    createMachine({
      types: {} as {
        context: { count: number };
      },
      context: {
        count: 0
      }
    });
    

Minor Changes

  • #4117 c7c3cb459 Thanks @davidkpiano! - Actor logic creators now have access to self:

    const promiseLogic = fromPromise(({ self }) => { ... });
    
    const observableLogic = fromObservable(({ self }) => { ... });
    
    const callbackLogic = fromCallback((sendBack, receive, { self }) => { ... });
    
    const transitionLogic = fromTransition((state, event, { self }) => { ... }, ...);
    
xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Minor Changes

xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #4130 e659fac5d Thanks @davidkpiano! - The pure(...) action creator is now properly typed so that it allows function actions:

    actions: pure(() => [
      // now allowed!
      (context, event) => { ... }
    ])
    
xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

  • #4127 cdaddc266 Thanks @Andarist! - IDs for delayed events are no longer derived from event types so this won't work automatically:

    entry: raise({ type: 'TIMER' }, { delay: 200 });
    exit: cancel('TIMER');
    

    Please use explicit IDs:

    entry: raise({ type: 'TIMER' }, { delay: 200, id: 'myTimer' });
    exit: cancel('myTimer');
    
  • #4127 cdaddc266 Thanks @Andarist! - All builtin action creators (assign, sendTo, etc) are now returning functions. They exact shape of those is considered an implementation detail of XState and users are meant to only pass around the returned values.

Patch Changes

  • #4123 b13bfcb08 Thanks @Andarist! - Removed the ability to configure transitions using arrays:

    createMachine({
      on: [{ event: 'FOO', target: '#id' }]
      // ...
    });
    

    Only regular object-based configs will be supported from now on:

    createMachine({
      on: {
        FOO: '#id'
      }
      // ...
    });
    
xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

  • #4050 fc88dc8e6 Thanks @davidkpiano! - The options prop has been added (back) to the Context.Provider component returned from createActorContext:

    const SomeContext = createActorContext(someMachine);
    
    // ...
    
    <SomeContext.Provider options={{ input: 42 }}>
      {/* ... */}
    </SomeContext.Provider>;
    

Minor Changes

  • #4050 fc88dc8e6 Thanks @davidkpiano! - The observerOrListener argument has been removed from the 3rd argument of createActorContext(logic, options).
xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

  • #4119 fd2280f4e Thanks @Andarist! - Removed the deprecated send action creator. Please use sendTo when sending events to other actors or raise when sending to itself.
xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #4080 94526df03 Thanks @davidkpiano! - The machine.options property has been renamed to machine.implementations

  • #4078 43fcdecf2 Thanks @Andarist! - Fixed spawned actors cleanup when multiple actors were spawned without explicit IDs assigned to them.

  • #4083 163528529 Thanks @Andarist! - Remove State['changed']. A new instance of State is being created if there are matching transitions for the received event. If there are no matching transitions then the current state is being returned.

  • #4064 047897265 Thanks @davidkpiano! - Guard objects can now reference other guard objects:

    const machine = createMachine(
      {
        initial: 'home',
        states: {
          home: {
            on: {
              NEXT: {
                target: 'success',
                guard: 'hasSelection'
              }
            }
          },
          success: {}
        }
      },
      {
        guards: {
          // `hasSelection` is a guard object that references the `stateIn` guard
          hasSelection: stateIn('selected')
        }
      }
    );
    
xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Minor Changes

  • #4098 ae7691811 Thanks @davidkpiano! - The log, pure, choose, and stop actions were added to the main export:

    import { log, pure, choose, stop } from 'xstate';
    
xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Minor Changes

  • #4065 3b4b1305a Thanks @benblank! - This change adds support for using "*" as a wildcard event type in machine configs.

    Because that event type previously held no special meaning, it was allowed as an event type both in configs and when transitioning and matched as any other would. As a result of changing it to be a wildcard, any code which uses "*" as an ordinary event type will break, making this a major change.

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

xstate - [email protected]

Published by github-actions[bot] over 1 year ago

Major Changes

  • #4018 c59bb6a72 Thanks @Andarist! - machine.initialState has been removed, you can use machine.getInitialState(...) instead

  • #4018 c59bb6a72 Thanks @Andarist! - machine.transition(...) and machine.getInitialState(...) require now an actorContext argument

  • #4063 e1f633ac9 Thanks @Andarist! - Removed State['transitions'].

  • #4018 c59bb6a72 Thanks @Andarist! - machine.transition no longer accepts state values. You have to resolve the state value to a State before passing it to machine.transition

  • #4041 50fe8cdd4 Thanks @davidkpiano! - Instances of "behavior" in the codebase have been replaced with "actor logic".

  • #4055 eb7c8b387 Thanks @davidkpiano! - The system can now be accessed in all available actor logic creator functions:

    fromPromise(({ system }) => { ... });
    
    fromTransition((state, event, { system }) => { ... });
    
    fromObservable(({ system }) => { ... });
    
    fromEventObservable(({ system }) => { ... });
    
    fromCallback((sendBack, receive, { system }) => { ... });
    
  • #4062 28603a07f Thanks @Andarist! - Removed State['event'].

  • #4059 bbea3bc4d Thanks @Andarist! - Removed State['actions']. Actions are considered to be a side-effect of a transition, things that happen in the moment and are not meant to be persisted beyond that.

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

xstate - @xstate/[email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #4043 bc1799b36 Thanks @ksv90! - Pass around TState['value'] type to Transition and .initial property of the machine configuration.