Replies: 3 comments
-
You could wrap this in an invoked actor and send events to the parent that in turn would execute |
Beta Was this translation helpful? Give feedback.
-
Thank you Andarist for reply. Can you provide some sample code for my case above so I can get this correctly? Thank you |
Beta Was this translation helpful? Give feedback.
-
I have recently stumbled upon a similar issue:- I was trying to update the machine context from within an invoked promise actor. I was aware that actions could be used to update context (see Assign action), but actions run outside of a promise and do not guarantee order. However, I have figured out the way to do it which I believe is the way the maintainer intended. Here is the invoked promise actor: submitJob: fromPromise(async ({ input }: { input: { name: string } }) => {
console.log('Starting submitJob', input);
return { jobuid: '123' };
}), And this is the state that invokes this actor: SubmitJob: {
invoke: {
src: 'submitJob',
input: ({ context }) => ({
name: context.job.name
}),
onDone: {
target: 'WaitForCompletion',
actions: assign({
jobuid: ({ event }) => event.output.jobuid
})
}
}
}, The secret sauce is to use the An excellent example that I drew from: |
Beta Was this translation helpful? Give feedback.
-
First, a big thank you for this awesome state management library.
I learnt like to update the context there is only one way and that is to use assign action.
My case is something like
actions:["doSomeStuffs"]
and on doSomeStuffs, I want to do something like
doSomeStuffs = (context, event) => {
//update context
await getSomeData()
//update context
await getSomeData2()
//update context
}
Here, I am not sure how can I update context. assign is an action so I can not directly call. I can do like to split doSomeStuffs into individual actions where I can use assign actions as per sequence I need. But I think there should be a better way of doing this.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions