Skip to content

Commit

Permalink
Let caller provider a logger tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Sep 25, 2021
1 parent 2b96c82 commit a57a431
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/new-statemachine.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
(let [state (get-state fsm)
{: current-state : context} state]
(if-let [tx-fn (get-transition-function fsm current-state action)]
; TODO: Have per-fsm logger
(let [
; TODO: Should we pass the whole state (current state and context) or just context?
transition (tx-fn state action extra)
Expand All @@ -61,7 +60,7 @@
; Call all subscribers
(each [_ sub (pairs (atom.deref fsm.subscribers))]
(sub {:prev-state state :next-state new-state : action : effect : extra})))
(log.wf "Action %s does not have a transition function in state %s" action current-state))))
(call-when fsm.log.wf "Action :%s does not have a transition function in state :%s" action current-state))))

(fn subscribe
[fsm sub]
Expand Down Expand Up @@ -101,7 +100,8 @@
(let [fsm {:state (atom.new {:current-state template.state.current-state :context template.state.context})
:states template.states
; TODO: Use something less naive for subscribers
:subscribers (atom.new {})}]
:subscribers (atom.new {})
:log (if template.log (hs.logger.new template.log "info"))}]
; Add methods
(tset fsm :get-state (partial get-state fsm))
(tset fsm :signal (partial signal fsm))
Expand Down Expand Up @@ -157,7 +157,8 @@
:open enter-menu}
:menu {:leave leave-menu
:back up-menu
:select enter-menu}}})
:select enter-menu}}
:log "modal FSM"})


;; Effect handlers
Expand Down

0 comments on commit a57a431

Please sign in to comment.