Options
All
  • Public
  • Public/Protected
  • All
Menu

An object used by process to determine which actions should be executed and under what circumstances.

see

transitions factory method

see

dependencies factory method

example
const actions = models.collection(
process.action('a', () => console.log('running a')),
process.action('b', () => console.log('running b')),
process.action('c', () => console.log('running c')),
);

const inParallel = {
getInitialActions(actions, context) {
return actions;
},
contextFromArgs(args) {
const value = args.shift();
return { key: value };
}
};

export const run = process.create('my process', actions, inParallel);
// USAGE: run('some value');

Hierarchy

  • ProcessLogic

Index

Methods

  • contextFromArgs(args: any[]): Record<string, any>
  • Generates the appropriate context object based on the arguments the user has passed to the ProcessStart method.

    example
    import { merge } from 'lodash';

    // use whatever arguments were passed to start() as the context;
    // e.g. start({key: 'value'}, {another: 'value'}) would return a
    // context that combines both those objects
    function contextFromArgs(args) {
    return merge({}, ...args);
    }

    Parameters

    • args: any[]

      The arguments the user passed to the ProcessStart method.

    Returns Record<string, any>

    An object that will be mixed into the running process's context and passed to any Action methods as this.

  • Returns an array of actions to run when the process is started. Return an empty array if the process should not do anything.

    example
    // retrieve the action at the index passed
    // to the start method returned by process(...)
    // -- e.g. start(3) uses the 4th action
    function getInitialActions(actions, context) {
    const index = context.args[0] || 0;
    const first = actions[index] || actions[0];
    return [ first ]; // always return an array
    }

    Parameters

    • actions: Action[]

      The actions available for the process.

    • context: ProcessContext

      Information about the running process.

    Returns Action[]

    An array of actions to run.

  • Returns an array of actions to run. This method is called when update is invoked (if no actions are currently running) as well as whenever the previous set of actions resolves. Return an empty array if the process should not do anything.

    example
    function getNextActions(actions, context) {
    // restrict parallel actions to a maximum of 5 at once:
    return actions
    .filter(action => !context.started.includes(action.name))
    .slice(0, 5);
    }

    Parameters

    • actions: Action[]

      The actions available for the process.

    • context: ProcessContext

      Information about the running process.

    Returns Action[]

    An array of actions to run.