Skip to content

customcommander/xmachina

Repository files navigation

https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg

XMachina

The goal of this project is to provide a concise yet declarative language for state machines and to augment the experience of working with XState.

At this stage this is an educational project only and I make no commitments to deliver anything useful at any time.

TL; DR

import {interpret} from 'xstate';
import {xmachina} from '@customcommander/xmachina';

const service =
  interpret(xmachina`
    machine question {
      is_valid = ${(ctx, ev) => ev.answer === 42}

      initial state searching {
        [ON_ANSWER]: is_valid? found
      }

      final state found {}
    }`);

service.start();

service.send({type: 'ON_ANSWER', answer: 10});
// still searching

service.send({type: 'ON_ANSWER', answer: 42});
// found answer!

Acknowledgment

When I initially set out to write this DSL, I didn’t look around for similar projects. However it didn’t take long until I came across Lucy.

I suspect that XMachina will look similar to Lucy in many ways, but it will also be different as I make my own design decisions.

I should also mention JSSM and FSL for completeness even though their goals are somewhat different than mine.

Nonetheless people will eventually notice the similarities and I just wanted to take this opportunity to thank and give credit to the people who were on this journey before me.

Thank you!