Black Lives Matter. Support the Equal Justice Initiative.


Fast 1kB functional library for creating Finite State Machines

# reduce

reduce takes a reducer function for changing the context of the machine. A common use case is to set values coming from form fields.

In this example are implementing a login form that sets the login and password properties on the context.

import { createMachine, reduce, state, transition } from 'robot3';

const machine = createMachine({
idle: state(
transition('login', 'idle',
reduce((ctx, ev) => ({ ...ctx, login: }))
transition('password', 'idle',
reduce((ctx, ev) => ({ ...ctx, password: }))
transition('submit', 'complete')
complete: state()