Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] Improve target resolution #2881

Merged
merged 17 commits into from
Apr 8, 2023
Merged

[v5] Improve target resolution #2881

merged 17 commits into from
Apr 8, 2023

Conversation

davidkpiano
Copy link
Member

@davidkpiano davidkpiano commented Dec 19, 2021

This PR improves target resolution:

  • 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'
  }
});
  • Delimiters in state node IDs resolve to the state node from the path relative to the resolved state node ID
createMachine({
  // ...
  on: {
    SOME_EVENT: '#foo.bar' // resolves to whatever.bar
  },
  states: {
    whatever: {
      id: 'foo',
      states: {
        bar: {} // resolves to this state node
      }
    }
  }
});

fixes #346

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2021

🦋 Changeset detected

Latest commit: c262492

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

This PR includes changesets to release 1 package
Name Type
xstate Major

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

@ghost
Copy link

ghost commented Dec 19, 2021

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

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@Andarist
Copy link
Member

Andarist commented Jan 2, 2022

Gonna test this asap - I've tried to do so a few days ago but the test output is spammed with some unrelated stuff and this made playing with it a little bit harder. Gonna take a second look on Monday or so and also I will try to clean up that test output.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 4, 2022

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 c262492:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

# Conflicts:
#	packages/core/src/StateMachine.ts
#	packages/core/src/stateUtils.ts
@Andarist Andarist merged commit 2f45343 into next Apr 8, 2023
@Andarist Andarist deleted the v5/target-resolution branch April 8, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants