You create a fsm via an effect:
(reg-event-fx
:id
(fn [_ _])
{:fsm {:create {:id 123
:initial-state {}
:log-fn (fn [fsm-db db trigger new-state] ...)
:start (fn [XXX] )
:on-complete (fn [XXX] )
:machine {
[:state1 :trigger :new-state :action :guard]
[:state1 :trigger :new-state :action :guard]
[:state2 :trigger :new-state :action
}
:terminal-states [:state2]
:actions {
:action (fn [fsm-db trigger] {:fsm-db)
}
:guards {
:guard-id (fn [fsm-db])
}
}
)
You trigger the FSM in one of two ways:
- Via an effect
- or via a dispatch to s special event handler
(dispatch [:fsm :id :trigger :other-args}])
I have to work out how actions can act like event handlers, but be syncronous.
Subscriptions:
(subscribe [:fsm :id :path-within-state])
fsm-db:
{:id XXX
:state XXX
:spec {} ;; read-only description of the machine
:data {}} ;; additional state matained by the machine
Notes:
- Where is fsm state stored? Has to be
app-db
- XXX is there a need for
on-start
. That should be - XXX how to know when complete
- XXX means installing an effect handler and special event handler so triggers can be
- XXX Will we need the ability to order effects?
- XXX