MaximGB/re-state a re-frame supplimentary library routing dispatched events via statecharts implementing finite state atomata

Hello, allow me to announce my first public OSS ClojureScript library

Re-state routes re-frame events via statechart interpreter, currently backed by XState library, thus allowing more fine grained event handling. A re-frame component might use a statechart interpreter to dispatch to and handle events related only to the component. The library also implements facilities to isolate component state within re-frame application database, thus making it possible to write real independent standalone components.

Documentation and examples can be found here: https://github.com/MaximGB/re-state
Real life example here: https://github.com/MaximGB/TetrisRF
GitHub: https://github.com/MaximGB/re-state
Clojars: https://clojars.org/maximgb/re-state

3 Likes

Very nice! I’ll see if I can use if in my next re-frame project. I’d maybe consider changing the name though - there’s another library called re-state which is broadly similar to yours (although it doesn’t look to be actively maintained).

I’ve got a couple of questions: is it possible to have nested state machines? And is there any way of visualising the state machine, like in fsm-clj?

Hello, DaveWM

Thanks for the response. At the time of writing the library I didn’t know about re-frame related project with the same name. I’ll probably change the library name shortly, though I’m not sure it will be version-vise correct, since I baldly have released 1.0.0 already.

Regarding nested state machines. Well right before release I decided to not include a functionality allowing to spawn and control other machines, it was implemented using re-frame effects/co-effects and frankly I thought its usefulness is limited. Can you give me a couple of use cases you might have for the feature? Also being a statechart implementation XState library (upon which re-state is build over) allows one to define nested states. Maybe that’s what you need. As for visualization, once again XState might help here. If you convert a machine config from CLJS to JS and pass the result to XState visualizer, which is available online, then you will have what you need.

1 Like

I don’t actually have a concrete use case for nested state machines sorry. The reason I asked is that I’ve previously used reduce-fsm on a backend Clojure project, and we were hampered to some degree by the lack of composability. Looking through the XState docs, it seems like you can combine multiple state machines into one so I imagine nested state machines are a bit useless, as you say.

Good to know you can visualise the state machines. It can be really useful to show non-technical people how your application works.