Skip to main content

Atom Workflow Activity

This activity is used to execute an atomic step, like send an email, set a counter etc. It's the most basic activity.

import { Step } from 'sequential-workflow-model';
import { createAtomActivity } from 'sequential-workflow-machine';

interface SetCounterStep extends Step {
type: 'setCounter';
componentType: 'task';
properties: {
value: number;
};
}

interface MyGlobalState {
counter: number;
}

interface MyActivityState {
x: number;
}

const setCounterActivity = createAtomActivity<SetCounterStep, MyGlobalState, MyActivityState>('setCounter', {
init: (step: SetCounterStep, globalState: MyGlobalState) => {
return {
x: -1
};
},
handler: async (step: SetCounterStep, globalState: MyGlobalState, activityState: MyActivityState) => {
globalState.counter = step.properties.value * activityState.x;
}
})

Many atomic steps don't need own activity state. For those activities you can use the createAtomActivityFromHandler function. It requires less parameters.

import { createAtomActivityFromHandler } from 'sequential-workflow-machine';

const setCounterActivity = createAtomActivityFromHandler<SetCounterStep, MyGlobalState>(
'setCounter',
async (step: SetCounterStep, globalState: MyGlobalState) => {
globalState.counter = step.properties.value;
}
)