0.0.2 • Published 5 years ago

@barakplasma/finite-state-machine v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status MIT license

Finite State Machine

Tiny finite state machine library for fun and profit. See the tests for more usage examples.

Using this module in other modules

Here is a quick example of how this module can be used in other modules. The TypeScript Module Resolution Logic makes it quite easy. The file src/index.ts is a barrel that re-exports selected exports from other files. The package.json file contains main attribute that points to the generated lib/index.js file and typings attribute that points to the generated lib/index.d.ts file.

  • To use the FSM class in a TypeScript file -
import { FSM } from "@barakplasma/finite-state-machine";

const anFSM = new FSM();

anFSM.addState('on');
anFSM.addState('off');

anFSM.on({ inputName: 'toggle' }, () => {
    return new Map([['on', 'off'], ['off', 'on']]);
});

const { dispatch } = anFSM;

dispatch({ inputName: 'toggle' });

anFSM.getCurrentState() // 'off'
  • To use the FSM class in a JavaScript file -
const FSM = require('my-amazing-lib').FSM;

const anFSM = new FSM();

anFSM.addState('on');
anFSM.addState('off');

anFSM.on({ inputName: 'toggle' }, () => {
    return new Map([['on', 'off'], ['off', 'on']]);
});

const { dispatch } = anFSM;

dispatch({ inputName: 'toggle' });

anFSM.getCurrentState() // 'off'

finite-state-machine

0.0.2

5 years ago

0.0.1

5 years ago