statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.98k stars 1.24k forks source link

[core] Add `meta` types #4863

Closed davidkpiano closed 5 months ago

davidkpiano commented 5 months ago

Meta objects for state nodes and transitions can now be specified in setup({ types: … }):

const machine = setup({
  types: {
    meta: {} as {
      layout: string;
    }
  }
}).createMachine({
  initial: 'home',
  states: {
    home: {
      meta: {
        layout: 'full' // strongly typed
      }
    }
  }
});

const actor = createActor(machine).start();

actor.getSnapshot().getMeta().home!;
// typed as { layout: string }

Fixes #809

changeset-bot[bot] commented 5 months ago

🦋 Changeset detected

Latest commit: f5466696b82ea9facaafe68905a3bfc383b3c345

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------ | ----- | | xstate | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jonestristand commented 5 months ago

This would be very useful to me!

davidkpiano commented 5 months ago

cc. @Andarist Quick review? 🥺

jonestristand commented 5 months ago

Amazing, thank you!