liblucy icon indicating copy to clipboard operation
liblucy copied to clipboard

[IDEA] XState JSON to Lucy?

Open santicros opened this issue 3 years ago • 8 comments

Hi!! Thanks for you work!! It's been fun playing with Lucy 😊

I was thinking would it be possible to generate Lucy files from XState JSON definitions? Not sure if it would be super complex or is something simple.

I thought about it as I was replicating my XState machines in Lucy manually :)

Thanks!

santicros avatar May 22 '21 22:05 santicros

Hey @santicros!

What's the use case here? Is this kind of like a codemod? I.e. take your existing machines and spit them out into Lucy? Wondering where we should prioritise this in terms of urgency.

mattpocock avatar May 23 '21 09:05 mattpocock

Hi @mattpocock!!

Yes, for mi this is zero urgent, but an idea for the future. Would be an addition to the command line, that passing a JSON generates a Lucy code. I see a bright future for Lucy together with XState and I think it can be a useful thing to have in the future, but zero urgent for now :)

santicros avatar May 23 '21 10:05 santicros

Thanks! So what I see a need for is:

  • Convert Lucy to JSON.
  • Convert JSON to Lucy.

I'm fully in favor of that. However, how will the JSON be used practically? If the visualizer had a JSON format that it could consume and produce that would make sense. You could build your machine in the visualizer, export as JSON, then convert to Lucy.

Does XState have such a format that it uses in the visualizer (or by any other tools)? This is where I want to hold off on this idea, until there's other tools using the JSON format (as a sort of intermediary) then I'm not sure what it's for in practice.

matthewp avatar May 23 '21 11:05 matthewp

@matthewp Not yet, but this is in the works. I do think that it'll be very similar to, or interoperable with, the machine config structure that we currently pass into XState's createMachine.

mattpocock avatar May 23 '21 12:05 mattpocock

Cool, is there a tracking issue for this?

matthewp avatar May 23 '21 15:05 matthewp

Yes!! I think it would be the object we pass to createMachine serialized. For reference, I see in this comment https://spectrum.chat/statecharts/general/how-to-serialize-a-machine-as-visualizable-json~94a8470a-c28d-4103-8137-9c8b081d9225 David explained how to serialize a XState machine.

santicros avatar May 23 '21 15:05 santicros

I asked about this idea here: https://github.com/davidkpiano/xstate/issues/293. If there's a better issue to track please share.

matthewp avatar May 24 '21 13:05 matthewp

This would also be a great idea for demonstrating the value proposition of Lucy (as it should really shine for more complex examples). I was searching for an online XState to Lucy translator as I wanted to see how https://codesandbox.io/s/xstate-todomvc-33wr94qv1?file=/todoMachine.js would look in Lucy.

redbar0n avatar Oct 21 '21 11:10 redbar0n