Concepts

Deterministic action replay

Try the free JavaScript compiler

Apply the same ordered actions to the same starting state to reproduce a deterministic reducer result.

Formal Syntax & Structure

javascript syntaxjavascript
actions.reduce(reducer, initialState)

Working Example

Example Snippetjavascript
(async () => {const reducer=(n,a)=>a.type==="INC"?n+a.by:a.type==="RESET"?0:n;const actions=[{type:"INC",by:3},{type:"RESET"},{type:"INC",by:2}];console.log(actions.reduce(reducer,0),actions.reduce(reducer,0));})()
JavaScript Reference