Add the dep to to your project.clj/deps.edn/shadow-cljs.edn:
The below document assumes you have a require
statement like this:
(require '[statecharts.core :as fsm])
There are two layers of APIs in clj-statecharts:
Simply define a machine, which includes:
And use the fsm/initialize
and fsm/transition
functions.
{{< loadcode "samples/src/statecharts-samples/basic_immutable.clj" >}}
Returns the initial state of the machine. It also executes all the entry actions of the initial states, if any.
If you do not want these actions to be executed, use (fsm/initialize machine {:exec false})
instead. The action functions would be collected in the _actions
key of the new state map. For example, the test code of clj-statecharts uses this
feature to make assertions to ensure correct actions are collected during
transitions.
Returns the next state based the current state & event. It also executes all the entry/exit/transition actions.
If you do not want these actions to be executed, use (fsm/transition machine state event {:exec false})
instead.
The immutable API provides a clean interface so you can integrate it into your own state management system like re-frame.
However, sometimes it's more convenient to provide a higher level API that could manage the state out of the box. Here comes the service API.
The usage pattern for the service API is very simple:
fsm/state
or fsm/value
to get the state of the service.{{< loadcode "samples/src/statecharts-samples/basic.clj" >}}
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close