API Docs for:
Show:

Utils.FSM Class

Module: Utils

Implementation of a simple finite state machine class

Item Index

Methods

Methods

FSM

() Object

Creates a Finite State Machine with addState(), removeState(), getState() and consume() methods

Returns:

Object:

Finite State Machine (FSM)

Example:

import FSM from './utils/fsm';

var fsm = FSM().
    addState({name: 'first', events: {next: 'second'}}).
    addState({name: 'second', events: {next: 'third', previous: 'first'}}).
    addState({name: 'third', events: {previous: 'second'}});

fsm.getState();
// -> 'first'

fsm.consume('next').getState();
// -> 'second'

fsm.consume('next').getState();
// -> 'third'

fsm.consume('next').getState();
// -> 'third', since third has no next event