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 - @xstate/[email protected]

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

Patch Changes

  • #4033 9cb7cb51a Thanks @Andarist! - Fixed generated TS declaration files to not include .ts extensions in the import/export statements.
xstate - [email protected]

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

Patch Changes

  • #4033 9cb7cb51a Thanks @Andarist! - Fixed generated TS declaration files to not include .ts extensions in the import/export statements.
xstate - [email protected]

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

Major Changes

  • #3990 fe6db147a Thanks @davidkpiano! - You can now add a systemId to spawned actors to reference them anywhere in the system.

    const machine = createMachine({
      // ...
      context: ({ spawn }) => ({
        actorRef: spawn(
          createMachine({
            // ...
          }),
          { systemId: 'actorRef' }
        )
      })
    });
    
  • #3991 98db493e4 Thanks @davidkpiano! - The actor.onDone(...) method is removed. Use actor.subscribe({ complete() {... } }) instead.

    - actor.onDone(() => { ... })
    + actor.subscribe({
    +  complete() {
    +    // ...
    +  }
    +})
    
xstate - [email protected]

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

Patch Changes

  • #4020 7898731b5 Thanks @davidkpiano! - The fromEventObservable actor logic creator now accepts input:

    const machine = createMachine({
      invoke: {
        src: fromEventObservable(({ input }) => /* ... */),
        input: {
          foo: 'bar'
        }
      }
    });
    
xstate - @xstate/[email protected]

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

Major Changes

  • #3947 5fa3a0c74 Thanks @davidkpiano! - Removed the ability to pass a factory function as argument to useMachine and useInterpret.

  • #4006 42df9a536 Thanks @davidkpiano! - useActorRef is introduced, which returns an ActorRef from actor logic:

    const actorRef = useActorRef(machine, { ... });
    const anotherActorRef = useActorRef(fromPromise(...));
    

    useMachine is deprecated in favor of useActor, which works with machines and any other kind of logic

    -const [state, send] = useMachine(machine);
    +const [state, send] = useActor(machine);
    const [state, send] = useActor(fromTransition(...));
    

    useSpawn is removed in favor of useActorRef

    -const actorRef = useSpawn(machine);
    +const actorRef = useActorRef(machine);
    
    The previous use of `useActor(actorRef)` is now replaced with just using the `actorRef` directly, and with `useSelector`:
    
    ```diff
    -const [state, send] = useActor(actorRef);
    +const state = useSelector(actorRef, s => s);
    // actorRef.send(...)
    
  • #4006 42df9a536 Thanks @davidkpiano! - useActor has been removed from the created actor context, you should be able to replace its usage with MyCtx.useSelector and MyCtx.useActorRef.

  • #3947 5fa3a0c74 Thanks @davidkpiano! - Implementations for machines on useMachine and useInterpret hooks should go directly on the machine via machine.provide(...), and are no longer allowed to be passed in as options.

    -const [state, send] = useMachine(machine, {
    -  actions: {
    -    // ...
    -  }
    -});
    +const [state, send] = useMachine(machine.provide({
    +  actions: {
    +    // ...
    +  }
    +}));
    

    @xstate/react will detect that the machine's config is still the same, and will not produce the "machine has changed" warning.

xstate - [email protected]

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

Major Changes

  • #3971 d0ba42ca9 Thanks @Andarist! - _event has been removed from all APIs and types. It was a wrapper structure containing the event that users were using directly.
xstate - [email protected]

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

Patch Changes

  • #3981 a225a474c Thanks @Andarist! - Fixed an issue with a referenced action responding to an initial raised event being called with init event
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

  • #3972 2b9583a63 Thanks @Andarist! - The "Some implementations missing" type-level error will now mention what implementations are missing.
xstate - @xstate/[email protected]

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

Patch Changes

  • #3919 6665f0a32 Thanks @c-w! - Updated the allowed range for the use-isomorphic-layout-effect dependency.
xstate - [email protected]

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

Major Changes

  • #898 26986f417 Thanks @davidkpiano! - Sending a string event to actor.send('some string') will now throw a proper error message.

  • #3957 423c5ab72 Thanks @davidkpiano! - The machine .schema property is now .types:

    const machine = createMachine({
      // schema: { ... }
      types: {} as {
        context: { ... };
        events: { ... };
        // ...
      }
    });
    

    And the .tsTypes property is now .types.typegen:

    const machine = createMachine({
      // tsTypes: { ... }
      types: {} as {
        typegen: {};
        context: { ... };
        events: { ... };
        // ...
      }
    });
    
  • #3968 eecb31b8f Thanks @davidkpiano! - The createEmptyActor() function has been added to make it easier to create actors that do nothing ("empty" actors). This is useful for testing, or for some integrations such as useActor(actor) in @xstate/react that require an actor:

    import { createEmptyActor } from 'xstate';
    
    const SomeComponent = (props) => {
      // props.actor may be undefined
      const [state, send] = useActor(props.actor ?? createEmptyActor());
    
      // ...
    };
    
  • #3966 61db63bf4 Thanks @davidkpiano! - You can now import the following from xstate:

    import {
      // actions
      // sendTo (removed)
      pure,
    
      // interpret helpers
      waitFor,
    
      // actor functions
      fromPromise,
      fromObservable,
      fromCallback,
      fromEventObservable,
      fromTransition,
    
      // guard functions
      stateIn,
      not,
      and,
      or
    }
    

    The send action was removed from exports; use sendTo(...) or raise(...) instead.

Patch Changes

  • #3959 ead287257 Thanks @davidkpiano! - Unresolved promises will now be properly persisted. The current behavior is to restart a promise that is unresolved.
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

xstate - @xstate/[email protected]

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

xstate - @xstate/[email protected]

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

xstate - [email protected]

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

Major Changes

  • #3952 ec300837e Thanks @davidkpiano! - The output data on final states is now specified as .output instead of .data:

    const machine = createMachine({
      // ...
      states: {
        // ...
        success: {
    -     data: { message: 'Success!' }
    +     output: { message: 'Success!' }
        }
      }
    })
    
  • #2881 2f45343c5 Thanks @davidkpiano! - Target resolution improvements: targeting sibling nodes from the root is no longer valid, since the root node has no siblings:

    createMachine({
      id: 'direction',
      initial: 'left',
      states: {
        left: {},
        right: {}
      },
      on: {
    -   LEFT_CLICK: 'left',
    +   LEFT_CLICK: '.left'
      }
    });
    
xstate - [email protected]

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

Major Changes

  • #3926 f9f692b2b Thanks @davidkpiano! - Restored state will no longer contain actions, since they are assumed to have already been executed. Actions will not be replayed.

    If you want to replay actions when restoring state, it is recommended to use an event sourcing approach.

xstate - @xstate/[email protected]

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

Major Changes

  • #3917 b8b44206e Thanks @Andarist! - Observing a service via service.subscribe(...) no longer immediately receives the current state. Instead, the current state can be read from service.state, and observers will receive snapshots only when a transition in the service occurs.
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

Patch Changes

  • #3944 305a89001 Thanks @Andarist! - Releasing adjusted internals to make the alpha version of this module compatible with the current version of xstate@alpha