question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In the AST, model activities more cleanly

See original GitHub issue

Expected Behavior

I’m trying to create a tool to create svg visualisations of xstate state machines.

To do this I’m attempting to convert xstate machine descriptions to State Machine Cat json, which I can then feed into State Machine Cat to generate an svg.

Alongside entry and exit triggers, xstate supports the idea of activities. At the moment State Machine Cat json has a hard coded list of acceptable trigger types, which only include entry and exit.

https://github.com/sverweij/state-machine-cat/blob/develop/src/parse/smcat-ast.schema.json#L29

Would it be possible to add activity (or some equivalent) to that list?

Steps to Reproduce (for bugs)

I can whip up a minimal example of the problem if that is useful!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
karlcommented, Sep 29, 2018

Awesome!

That is exactly how I was modelling it in my head, so I’m very happy with that change 😀 On Sat, 29 Sep 2018 at 6:04 pm, Sander Verweij notifications@github.com wrote:

I’ve been struggling with keeping the ordering as entered, but the code became really messy. So I had to get back to base 1: the model wasn’t good enough yet. entry and exit’s are similar to activities - but in the model they weren’t.

I took a look at the Harel’s original state chart paper - and noticed he calls all three of them actions (similar to the same concept on transitions). So I decided to

  • rename triggers to actions
  • move activities under the actions with activity as type

… which results in this AST for the above sample:

{ “states”: [ { “name”: “play”, “type”: “regular”, “actions”: [ { “type”: “entry”, “body”: “make some noise” }, { “type”: “activity”, “body”: “blink a light” }, { “type”: “activity”, “body”: “do something funny” }, { “type”: “exit”, “body”: “click” } ] } ] }

Published as 3.0.4-beta-2 on npm.

(I’ve taken the liberty to update redux-saga-state-machine/xstate-to-svg and retest it, and it seems to work OK, provided jest -u is run to update the snapshot so it expects the new (more correct) order of actions is - diff here https://gist.github.com/sverweij/238ac58539cecec834fab8e14f1e13f2/revisions

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sverweij/state-machine-cat/issues/22#issuecomment-425660154, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAOYSXH17Vqkxs0fRADTpRZDqy0azUOks5uf6gSgaJpZM4W26S0 .

0reactions
sverweijcommented, Sep 29, 2018

I’ve been struggling with keeping the ordering as entered, but the code became really messy. So I had to get back to base 1: the model wasn’t good enough yet. entry and exit’s are similar to activities - but in the model they weren’t.

I took a look at the Harel’s original state chart paper - and noticed he calls all three of them actions (similar to the same concept on transitions). So I decided to

  • rename triggers to actions
  • move activities under the actions with activity as type

… which results in this AST for the above sample:

{
    "states": [
        {
            "name": "play",
            "type": "regular",
            "actions": [
                {
                    "type": "entry",
                    "body": "make some noise"
                },
                {
                    "type": "activity",
                    "body": "blink a light"
                },
                {
                    "type": "activity",
                    "body": "do something funny"
                },
                {
                    "type": "exit",
                    "body": "click"
                }
            ]
        }
    ]
}

Published as 3.0.4-beta-2 on npm.

(I’ve taken the liberty to update redux-saga-state-machine/xstate-to-svg and retest it, and it seems to work OK, provided jest -u is run to update the snapshot so it expects the new (more correct) order of actions is - diff here)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Time-Driven Activity-Based Costing - Harvard Business Review
Time equations greatly simplify the estimating process and produce a far more accurate cost model than would be possible using traditional ABC techniques....
Read more >
Activities of Daily Living - StatPearls - NCBI Bookshelf
Activities of daily living (ADLs) are essential and routine tasks that most young, healthy individuals can perform without assistance.
Read more >
Top ten ways to clean your data - Microsoft Support
Misspelled words, stubborn trailing spaces, unwanted prefixes, improper cases, and nonprinting characters make a bad first impression.
Read more >
Progress Cleaning the Air and Improving People's Health
A key reason is that the motor vehicle fleet is much cleaner because of Clean Air Act emissions standards for new motor vehicles....
Read more >
Webinars - Climate Literacy and Energy Awareness Network
All CLEAN webinars are virtual and use the online Zoom platform with screen share and integrated audio. For questions, more information, or to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found