elsa-workflows/elsa-designer

Activity Definitions as plain objects

sfmskywalker opened this issue · 1 comments

Although activity definitions are already defined as simple objects, one of the object's fields, getOutcomes, is actually a function. This makes it impossible to allow one to define activity definitions truly as data.

To fix this, I will change this field's type from a function to a union type of Array<string> | string. When the value is an array, each item is treated as a possible outcome. If the value is a string, it is interpreted as a lambda that will be evaluated at design-time in the designer.

Example using an array as outcomes:

{
   "type": "WriteLine",
   "displayName": "Write Line",
   "description": "Writes a message to the standard output",
   "category": "Console",
   "outcomes": ["Done"]
}

Example using a lambda as outcomes:

{
   "type": "Fork",
   "displayName": "Fork",
   "description": "Forks execution into multiple branches",
   "category": "Control Flow",
   "outcomes": "activity => activity.state.branches"
}

When the lambda is evaluated, the designer will pass in the activity for which the outcomes are being requested. This is important for activities such as Fork, because it enables the user to define the possible branches from the designer. The lambda can use this information to yield the possible outcomes.

Fixed as part of 5b5dae1