Class Context

Description

Create context and run scenarios

Example

import { Scenario, Context, step } from '@biorate/run-context';

export class Scenario1 extends Scenario {
@step()
protected async step1() {
this.ctx.set('step1', true);
}

@step()
protected async step2() {
this.ctx.set('step2', 1);
}
}

export class Scenario2 extends Scenario {
@step()
protected async step3() {
this.ctx.set('step3', false);
}
}

(async () => {
const ctx = await Context.run([Scenario1, Scenario2], { initial: 'value' });
console.log(ctx.get<boolean>('step1')); // true
console.log(ctx.get<number>('step2')); // 1
console.log(ctx.get<boolean>('step3')); // false
console.log(ctx.get()); // {
// 'step1': true,
// 'step2': 1,
// 'step3': false
// }
})();

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

#ctx: Record<string, any> = {}
metaKey: symbol = ScenarioSymbol

Methods

Generated using TypeDoc