Skip to content

Machines from lists

StateMachine.fromList creates transitions that steps through a series of states and then terminates.

import { StateMachine } from "https://unpkg.com/ixfx/dist/flow.js"
// Machine that can go: init -> one -> two -> three -> [end]
const sm1 = StateMachine.init(StateMachine.fromList(`init`, `one`, `two`, `three`));

Once in the ‘three’ state, will be considered done, since there is no possible transition from there.

StateMachine.fromListBidirectional is the same idea, but allow back-and-forth between states.

// Machine that can go: init <-> one <-> two <-> three
const sm2 = StateMachine.init(StateMachine.fromListBidirectional(`init`,`one`, `two`, `three`));

In the above example, sm2 will never be done, because it’s always possible for it to transition to some state.