Variable number of parallel states, how to re-use actions? #1315
-
I have a parallel state with a variable number of child compound states. Each compound state invokes a service and appends its data to the context on success. The event determines which subset of services will be invoked. If I have 5 services, the event may indicate that services 1, 3, and 5 are to be invoked. I have defined individual service implementations for each service:
However where I want to reuse implementations is in the actions that update the machine's context with the data returned from the services. I do not want to define an action for each service just to append its data to the context like this:
However, I do not see a way to send a variable to an action implementation. If I could do this I would send it the service's name and use that name as the key to add to the context with the data beneath it. Am I missing a way to pass data to an action? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Answering my own question. I had read this line from the actions documentation which states Example solution:
|
Beta Was this translation helpful? Give feedback.
Answering my own question. I had read this line from the actions documentation which states
Each action object has two properties (and others, that you can specify)
but it didn't dawn on me that this means I can put arbitrary properties which can be read from the exec's meta argument. This solves my issue. I'll leave this here instead of deleting the question in case it can be of help to someone else.Example solution: