From 820d81847b9ccc392aa73e4b98a05cf92ec31c4e Mon Sep 17 00:00:00 2001 From: Grazfather Date: Sat, 25 Sep 2021 18:09:57 -0400 Subject: [PATCH] Let caller provider a logger tag --- lib/new-statemachine.fnl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/new-statemachine.fnl b/lib/new-statemachine.fnl index 4cfcdf0..3c3ad25 100644 --- a/lib/new-statemachine.fnl +++ b/lib/new-statemachine.fnl @@ -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) @@ -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)))) + (if fsm.log (fsm.log.wf "Action :%s does not have a transition function in state :%s" action current-state))))) (fn subscribe [fsm sub] @@ -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)) @@ -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