#Persisting state - what to stringify

1 messages · Page 1 of 1 (latest)

ember coral
pastel bay
#

That can come e.g. from .subscribe:

const actor = interpret(machine).start();
actor.subscribe(state => {
  const jsonState = JSON.stringify(state);

  // ...
});
ember coral
#

Thanks. This makes sense. I have a state machine that has a child state machine. I want to get the parent's state and the child's state. I was hoping the state object (as in your example) would let me access that but I don't think it does.

I think I need to research the actor model now and figure out how to update the parent with the child's state, am I on the right track?

Is there some other way to do this that I should look into?

Any help is appreciated.

pastel bay
#

I'll get back to you on this soon

pastel bay
#

So reading the state snapshot of a child actor is done via .getSnapshot(); e.g. if you invoked an actor with the id 'test', it would be:

// parent state
// v
state.children['test'].getSnapshot()
//                     ^
//                 child snapshot