Black Lives Matter. Support the Equal Justice Initiative.


Fast 1kB functional library for creating Finite State Machines

# action

action takes a function that will be run during a transition. The primary purpose of using action is to perform side-effects.

This example triggers an event on an element when transitioning to the next state.

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

function dispatchOn(ctx) {
const { element } = ctx;
element.dispatchEvent(new CustomEvent('toggled'));

const machine = createMachine({
on: state(
transition('toggle', 'off')
off: state(
transition('toggle', 'on',
}, () => ({
element: document.querySelector('#toggler')