Concepts

Explicit state transition

Try the free JavaScript compiler

Define legal state-event pairs and a documented invalid-event behavior.

Formal Syntax & Structure

javascript syntaxjavascript
transition(state, event) → nextState

Working Example

Example Snippetjavascript
(async () => {const step=(s,e)=>e==="RESET"?"idle":s==="idle"&&e==="START"?"loading":s==="loading"&&e==="SUCCESS"?"ready":s==="loading"&&e==="FAILURE"?"error":s;console.log(step("idle","SUCCESS"),step("idle","START"),step("loading","FAILURE"));})()
JavaScript Reference