xstate icon indicating copy to clipboard operation
xstate copied to clipboard

[v5] Add `.stateNode` for actions and guards

Open davidkpiano opened this issue 2 years ago • 3 comments

The stateNode where an action or guard originates can now be read in the action or guard's provided implementation, or inline:

const machine = createMachine({
  initial: 'idle',
  states: {
    idle: {
      meta: { message: 'I am idle', enabled: true },

      entry: ({ stateNode }) => {
        stateNode.message; // 'I am idle'
      },

      on: {
        someEvent: {
          guard: ({ stateNode }) => {
            return stateNode.enabled; // true
          }
        }
      }
    }
  }
});

davidkpiano avatar Aug 28 '23 19:08 davidkpiano

🦋 Changeset detected

Latest commit: c1d81a956831fad2469fd97fce54ea759d525bbd

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

changeset-bot[bot] avatar Aug 28 '23 19:08 changeset-bot[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c1d81a956831fad2469fd97fce54ea759d525bbd:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

codesandbox-ci[bot] avatar Aug 28 '23 19:08 codesandbox-ci[bot]

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

ghost avatar Aug 28 '23 19:08 ghost