npm.io
2.1.3 • Published 3 weeks ago

@biorate/run-context

Licence
MIT
Version
2.1.3
Deps
3
Size
14 kB
Vulns
0
Weekly
0
Stars
5

Run context

Contexted scenarios execution by Middleware-based template

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.all()); // {
  //    'step1': true,
  //    'step2': 1,
  //    'step3': false
  //  }
})();

Learn

  • Documentation can be found here - docs.
Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)