Have ideas to improve npm?Join in the discussion! »

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

    0.0.3 • Public • Published

    Awesome Finite State Machine

    Build Status

    This is a simple finite state machine built on Typescript

    Roadmap

    • Make state domain objects inmutable
    • Create builders to construct a state machine easier
    • Be able to start from an existing machine definition to extend it, creating a new state graph
    • Machine state verification (All states are reachable, all transitions have origin/destination a valid state, etc)
    • Add rxjs and create observables for state changes and transition triggering

    Usage

    Simply basic usage (v0.0.1)

     
     const createMachine = () => {
        const machine = new RawStateMachine<string>({ name: 'a', data: 'A' });
        machine
          .addNode('a')
          .addTransition('a-to-b', 'b', () => 'B-FROM-A')
          .addTransition('a-to-c', 'c', () => 'C-FROM-A');
        machine
          .addNode('b')
          .addTransition('b-to-c', 'c', () => 'C-FROM-B')
          .addTransition('b-to-a', 'a', () => 'A-FROM-B');
        machine
          .addNode('c')
          .addTransition('c-to-b', 'b', () => 'B-FROM-C');
        return machine;
    };
     
    const machine = createMachine();
    machine.dispatch({ name: 'a-to-b' });
    machine.dispatch({ name: 'b-to-c' });
    machine.dispatch({ name: 'c-to-b' });
    machine.dispatch({ name: 'b-to-a' });

    Install

    npm i awsm-fsm

    DownloadsWeekly Downloads

    1

    Version

    0.0.3

    License

    ISC

    Unpacked Size

    2.34 kB

    Total Files

    2

    Last publish

    Collaborators

    • avatar