UNPKG

float-sidebar

Version:

A lightweight (2kb gzipped), zero-dependency javascript library for making a sidebar float

21 lines (15 loc) 490 B
function createFSM({ actions, transitions, initialState }) { let currentState = initialState; let findTransitionFor = (...args) => { return transitions[currentState] .find(({ when }) => { return when(...args).every((condition) => condition); }); } let performTransition = ({ to: newState }) => (...args) => { currentState = newState; actions[newState](...args); } return { findTransitionFor, performTransition }; } export default createFSM;