Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/customcommander/xmachina

A small DSL that compiles to XState.
https://github.com/customcommander/xmachina

dsl finite-state-machine state-machine tagged-template xstate

Last synced: 19 days ago
JSON representation

A small DSL that compiles to XState.

Awesome Lists containing this project

README

        

[[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 [[https://github.com/statelyai/xstate][XState]].

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

** TL; DR

#+begin_src javascript
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!

#+end_src

** 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 [[https://github.com/lucydsl/liblucy][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 [[https://github.com/StoneCypher/jssm][JSSM]] and [[https://fsl.tools/][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!