mattpocock / xstate-catalogue

Professionally designed, interactive state machines
https://xstate-catalogue.com
MIT License
811 stars 62 forks source link

New Feature Idea 💡 - Reset the Machine #39

Open bemayr opened 3 years ago

bemayr commented 3 years ago

After working with the Catalogue quite a bit I encountered some situations where I wanted to reset the state machine. If I am the only one not being satisfied by hitting F5 in this case then please ignore and close this PR 😉!

During research on how to implement this I stumbled upon @mattpocock's comment regarding this on discord asking what is the best way to restart a service.

Implementing took a little while because of https://github.com/davidkpiano/xstate/issues/2084, which (1) has a workaround for now (that's the initial empty contexts) and (2) will be integrated in an upcoming version of @xstate/react.

vercel[bot] commented 3 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mattpocock/xstate-catalogue/BoaNfJLf3FA6CzTEddPmgRySRpmG
✅ Preview: https://xstate-catalog-git-fork-bemayr-feature-reset-machine-mat-abcacc.vercel.app

bemayr commented 3 years ago

I've got three [~two~] comments regarding the code:

  1. I am not 100% happy with the inspector/start and stop service part of the code, if somebody has an idea on how to improve this I would be more than glad! 😊
  2. And the way this works now, examples with a random initial state (like Create / Update Form) do not receive a new initial state when hitting reset. The reason for this is that the machines are passed down via props and created using createMachine(...) somewhere else. Any thoughts on this?
  3. Feel free to change anything about the placement/design of the Reset Machine Button! 💅
mattpocock commented 3 years ago

@bemayr Good idea! This is for sure an important feature.

I'm not seeing it working on this link:

https://xstate-catalog-git-fork-bemayr-feature-reset-machine-mat-abcacc.vercel.app/machines/form-input

Will take a look at the code at some point, on my todo list

bemayr commented 3 years ago

Thanks for your answer Matt and looking into this!

I'm not seeing it working on this link: https://xstate-catalog-git-fork-bemayr-feature-reset-machine-mat-abcacc.vercel.app/machines/form-input

What exactly is not working for you there? Because for me the button is there and it resets the machine...? 🤔