elsa-workflows / elsa-designer

A standards-based Workflow Designer built with StencilJS
MIT License
263 stars 89 forks source link

Activity Definitions as plain objects #5

Closed sfmskywalker closed 5 years ago

sfmskywalker commented 5 years ago

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.

sfmskywalker commented 5 years ago

Fixed as part of 5b5dae1d0d40088e59b82211e21aa97a2b7d619e