npm i @bleckert/state
or yarn add @bleckert/state
import Machine from '@bleckert/state';
const machine = new Machine({
IDLE: {
on: {
send: 'SENDING',
},
},
SENDING: {
on: {
sent: 'SENT',
failed: 'ERROR',
},
},
SENT: {
final: true,
},
FAILED: {
on: {
retry: 'SENDING',
},
},
});
machine.onState('SENDING', console.log);
machine.dispatch('send');