Class: Workflow

Workflow(name, id, steps, custom)

The main workflow execution class, defined by the given definitions file. Initial state is pending, until `start()` is called. Hooks will not run when pending. Next step is defined either by `next` being defined in the current step or by user explicitly set the name or index of the step. It's up to you to handle permissions for any of these methods. Emits various events, see the respective method documentation.

Constructor

new Workflow(name, id, steps, custom)

Creates a new instance. Any properties in the definitions, hat are not one of name, id or steps are considered "custom" and are (optionally) handled by their respective extensions (if registered).
Parameters:
Name Type Description
name string name of the workflow
id string identifier of this instance of the workflow (in case you run multiple of the same)
steps object the workflows step definitions
custom object contains all custom properties of this workflow's definitions
Source:
See:
Throws:
if steps are not defined or have length of 0
Type
TinyflowError

Members

current :Step|null

The current step
Type:
Source:

Methods

cancel()

Completes the workflow but also wiped it's data and sets state as "cancelled"
Source:
Fires:
  • end - the workflow has ended,event: see the state property for in which state it ended

complete()

Completes the workflow, sets the current step to null and the state to "complete". Does not delete the workflow data as opposed to the cancel event
Source:
Fires:
  • end - the workflow has ended,event: see the state property for in which state it ended

start(ifopt)

Starts the workflow, runs through all extensions. Extensions are caught in a separate Microtask (Promise.catch) and will not cause the workflow start to cancel. Sets thw workflow state to "active"
Parameters:
Name Type Attributes Description
if autoStep <optional>
set to false it will not automatically step into the first available step
Source:
Fires:
  • started - when the workflow instance has successfully started (state became 'active')
Throws:
if the state is other than "pending"
Type
TinyflowError

step(indexOrName, optionsopt)

Sets a given step by name or index as the new current one. This method is for manually setting the next step. If you want the engine to automatically set the next step you should rather end the current step using {Step.prototype.complete} or {Step.prototype.cancel}! When a new step is set, the current step will be disposed properly, so you don't have to do it. Will listen to the new step's "end" event and automatically determine the next step to choose or to end the workflow.
Parameters:
Name Type Attributes Description
indexOrName string | number | null index of the step in linear flows or name of the step in non-linear flows
options object <optional>
Properties
Name Type Attributes Description
stepId string <optional>
an optional
autoOnEnd boolean <optional>
set to true to prevent workflow from automatically handling the next step if the current step ends
Source:
Fires:
  • event:step - when the new step is properly set up and active
Throws:
if no step is found by index or name
Type
TinyflowError