@chkt/states
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Tests Version Node Dependencies Licence Language Size

States

Install

npm install @chkt/states

Use

states is a minimalistic state machine consisting of declared and undeclared states, written in typescript. Each named state consists of a transform function and a list of one or more target states.

When transitioning from one state to the next, the transform function of the current state is run. Its return value will determine the next target state.

Undeclared states represent states without any targets to transition into.

import * as assert from 'assert';
import * as states from '@chkt/states';

const map = states.create({
    state : {
        transform : (context, next) => Promise.resolve(next.default(context)),
        targets : [{ id : 'undeclared_state' }]
    }
});

const contextToState = states.bindContextToState(map, 'state');
const end = contextToState({ foo : 'bar' });

assert.deepStrictEqual(end, {
    id : 'unnamed_state',
    context : { foo : 'bar' }
});

Dependents (1)

Package Sidebar

Install

npm i @chkt/states

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

15 kB

Total Files

14

Last publish

Collaborators

  • chkt