statetastic
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

statetastic

Finite state machine implementation in TypeScript.

Install

With npm: $ npm i rxjs statetastic --save

With yarn: $ yarn add rxjs statetastic

Usage

Define your state classes. Simple states can be extended from SimpleState:

export class MyStep extends SimpleState {
  run() {
    console.log('MyStep is up and running!');
    this.stateMachine.next();
  }
}

Extend from State instead if you want to handle additional state life-cycle events onEnter and onExit.

Next, configure state machine with FsmFactory:

const fsm = FsmFactory.create([
  new MyStep(),
  new MyOtherStep()
]);

Finally, run the machine and listen for it to finish:

fsm.start().subscribe(() => console.log('Finished!');

Check src/tests/journeys/async.spec.ts for a more complex example.

Readme

Keywords

none

Package Sidebar

Install

npm i statetastic

Weekly Downloads

0

Version

0.1.0

License

none

Unpacked Size

32.2 kB

Total Files

46

Last publish

Collaborators

  • aux