Skip to content

Instantly share code, notes, and snippets.

@mike-thompson-day8
Last active February 24, 2019 01:53
Show Gist options
  • Save mike-thompson-day8/d18d82ef43f53dc18f6612b247e39142 to your computer and use it in GitHub Desktop.
Save mike-thompson-day8/d18d82ef43f53dc18f6612b247e39142 to your computer and use it in GitHub Desktop.

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:

  1. Via an effect
  2. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment