matthewp / robot

🤖 A functional, immutable Finite State Machine library

Home Page:https://thisrobot.life

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

matches API

matthewp opened this issue · comments

This is something I've been experimenting with in a personal project. It would work something like this:

import {
  createMachine,
  invoke,
  state,
  state as final,
  transition
} from 'robot3';

machine = createMachine({
  idle: state(
    transition('next', 'upload')
  ),
  upload: invoke(createMachine({
    one: state(transition('next', 'done'))
    done: final()
  }), transition('done', 'idle')
})

service.matches('idle'); // true

service.send('next');

service.matches('idle'); // false
service.matches('upload.one'); // true

Oops! I forgot about #56