Open farukfakcin opened 1 year ago
Hi, thanks for bringing it up. This would indeed be a useful feature.
Thanks for providing a link to xstate docs. There are some caveats with saving and restoring state as stated in these docs but it should be no problem incorporating it into my node-red wrapper.
I think a sensible implementation would use node red‘s storage functionality. I‘ll have to look into it.
Some care has to be taken in order to make it work correctly within subflows as well (i.e. multiple instances of the same node).
Thank you for taking the feature into your plan. I wish I could help.
thanks in advance
Hi, any proceedings?
I did do some conceptual and proof-of-concept work. The feature will definately be coming. My lack of free time makes progress super slow, unfortunately.
Thank you for your patience!
another solution to my problem is having an input function with a "restore" topic and a payload of required initial state. i.e. I focused on restoring rather than persisting the state.
The following changes on restartMachine
if( msg.topic === "restore" ) restartMachine( node , msg.payload);
needs a change on method signature
function restartMachine(node, initialState = undefined)
will start service with initialState
if(initialState !== undefined) service.start(initialState);
This function will be called with a "restore" topic from other flow nodes. They need access to the internal xstate status object to use as initialState laters. The node should attach the internal xstate status object to the status change payload.
let payload = { state: state.value, changed: state.changed, done: state.done, activities: state.activities, actions: state.actions, event: state.event, context: state.context, stateObj: state };
That solved my need. I may contribute to your code, thanks.
Hi there,
I am using "node-red-contrib-xstate-machine" plugin for a while now. It is very enjoyable, thanks for your effort.
My flow will be used on our production line and the state of the stations on the line is managed by the plugin.
Now I have a need to to presist the xstate nodes, as the flow might be restarted from time to time.
Is there a way to persist the state of the node like mentioned in https://xstate.js.org/docs/guides/states.html#persisting-state ?
Thanks in advance, Ferhat