Minimal (neto) implementation of a state machine in javascript