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

Refactor how builtin actions are structured and how all actions are stored and resolved #4127

Merged
merged 12 commits into from
Jul 10, 2023

Conversation

Andarist
Copy link
Member

@Andarist Andarist commented Jul 7, 2023

No description provided.

@Andarist Andarist requested a review from davidkpiano July 7, 2023 15:34
@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2023

🦋 Changeset detected

Latest commit: bfa0e30

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 7, 2023

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

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

@ghost
Copy link

ghost commented Jul 7, 2023

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

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@davidkpiano
Copy link
Member

Looked mainly at the tests; LGTM but CI needs to pass

@@ -365,7 +354,7 @@ export function formatTransition<
}
const transition = {
...transitionConfig,
actions: toActionObjects(toArray(transitionConfig.actions)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is toActionObjects no longer called? A string "action" should be converted to { type: 'action' }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also what is causing the test failures, I believe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is toActionObjects no longer called? A string "action" should be converted to { type: 'action' }

Why? :p I mean, this isn't really strictly needed for quite anything (as showcased by this PR). I could add back this particular conversion but I wonder if it's worth it. From the types PoV, this makes the publicly accepted action different from the one that we operate on internally and right now both can just use Action and it's pretty easy to work with.

This is also what is causing the test failures, I believe

One test was related to the lack of .type on builtin actions - just fixed it. There wasn't any test that would test that actions are called with an object form of the action even if it was configured as string though - just added one and pushed out a fix for it.

The second one is related to JSON schema serialization. I didn't exactly dig into what has changed and what it would take to fix it right now. I think it's worth considering just removing this test for now (and perhaps the JSON schema as well). We can always bring this back later but right now this relies on the fact that actions are always objects but with this PR they are not. I think it would be better to remove toJSON methods and implement converting logic in something akin to machineToJson. It would also be good to specify what's the goal of this JSON schema and what one could actually do with it today.

Copy link
Member Author

@Andarist Andarist Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being I fixed the JSON serialization - changes around this can be moved to other discussions/PRs.

Copy link
Member

@davidkpiano davidkpiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, otherwise LGTM

@Andarist Andarist merged commit cdaddc2 into next Jul 10, 2023
3 checks passed
@Andarist Andarist deleted the actions-refactor branch July 10, 2023 09:13
@github-actions github-actions bot mentioned this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants