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

Built-in actions are omitted in JSON export #236

Open
dnna opened this issue May 28, 2024 · 3 comments
Open

Built-in actions are omitted in JSON export #236

dnna opened this issue May 28, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@dnna
Copy link

dnna commented May 28, 2024

Description

When creating a state machine that contains built-in actions such as assign, spawnChild etc and then export as JSON they get omitted.

Expected result

I'd expect built-in actions to carry over, as they are foundational functions and there is no way to for example assign a value through a JSON definition otherwise.

Actual result

Built-in functions are treated the same way as inline functions and get omitted.

Which browsers are you seeing the problem on?

No response

Additional details

No response

@dnna dnna added the bug Something isn't working label May 28, 2024
@davidkpiano
Copy link
Member

How do you expect the built-in actions to look like?

@dnna
Copy link
Author

dnna commented Jun 2, 2024

Good question, personally I'd say using actions objects the way they are defined here https://stately.ai/docs/actions#action-objects

Some types would just be reserved for built-in actions such as assign, sendTo, spawnChild, etc

e.g.

...
"actions": [
  {
    "type": "assign",
    "params": { "count": 5 }
  }
],
...

Of course it wouldn't be possible to represent more complex structures such as using event variables or function calls (but in that case one could argue JSON is just not the right format to define the state machine anyway), but for basic definitions such as spawning a child actor and sending it static messages it would work fine.

@davidkpiano
Copy link
Member

This may look like this:

{
  "type": "@xstate.assign", // "@xstate" namespace would be reserved
  "params": {
    "assignments": {
      "count": {
        "$type": "function",
        "value": "({ context, event }) => context.count + event.by"
      }
    }
  }
}

(thinking out loud)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants