statelyai / studio-issues

Report issues found in Stately Studio
5 stars 0 forks source link

Built-in actions are omitted in JSON export #236

Open dnna opened 1 month ago

dnna commented 1 month ago

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

davidkpiano commented 1 month ago

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

dnna commented 1 month ago

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 commented 3 weeks ago

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)