davestewart / javascript-state-machine

An expressive, feature-rich, event-driven JavaScript finite-state machine
http://statemachine.davestewart.io
342 stars 25 forks source link

Question: Serialise / deserialise state #19

Closed subcontact closed 6 years ago

subcontact commented 6 years ago

Hi, Sorry for raising an issue - I was't sure where to ask the question...

I'm looking for a simple way (API?) to be able to save/serialise the state externally and then create a new state machine at a later time (possible separate process) using the previously saved state.

It's for use in a stateless context over multiple executions. Any pointers/suggestions?

Great project by the way!

davestewart commented 6 years ago

Hey,

Thanks for the kind words!

It's been ages since I looked at the code, but could you save the base options as JSON, then set the initial state as the current state?

You could then save / restore this from JSON.

As for doing something more advanced with serialising and hydrating the state, that might be a good feature request. But as I said, I haven't looked at the code for ages, so can't advise on how much work that would / wouldn't be right now!

subcontact commented 6 years ago

Thanks for the quick response! That's enough for me to go with. Cheers