This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-21
Channels
- # calva (11)
- # cider (4)
- # clojure (15)
- # clojure-europe (20)
- # clojurescript (14)
- # clr (45)
- # conjure (2)
- # cursive (1)
- # fulcro (10)
- # helix (4)
- # honeysql (7)
- # hoplon (21)
- # humbleui (2)
- # hyperfiddle (23)
- # introduce-yourself (1)
- # malli (11)
- # matrix (3)
- # off-topic (6)
- # pathom (2)
- # practicalli (1)
- # re-frame (9)
- # releases (1)
- # specter (2)
- # sql (10)
- # xtdb (2)
hello there! I am interested in FSMs and I found https://github.com/day8/re-frame/blob/master/docs/EPs/005-StateMachines.md. Since last update was 2018, is it still considered? Thanks!
Check out https://github.com/lucywang000/clj-statecharts It also contains a namespace to work with re-frame
Hello again. I'm learning about https://github.com/lucywang000/clj-statecharts and I have a question in regard to the state that is passed to Guarded Transitions' condition-fn
, what state is passed to this predicate? Is it the same as the one passed to actions
? Both say state is the current state
and I'm confused? Thank you.
It’s documented here https://lucywang000.github.io/clj-statecharts/docs/concepts/#the-state-map
So it’s something about the current state of the machine + any other data you might’ve wanted to associate with it.
hello, thanks for your answer but I think you didn't get my question. If you read https://lucywang000.github.io/clj-statecharts/docs/actions/#the-special-variable-_prev-state-in-action-functions, they tell you the state passed to actions is not the state before the trigger/event but the new state aka the state not gonna change after this in this transition.
how do you pass the current state to guard conditions if there are two possibilities and we don't know which one is gonna be the next state yet until the guard function is run. It leaves me with one conclusion, guard functions take the previous state not current, or I'm misunderstanding everything.
What is the current state
? is it the state the machine is in before an event occurs or the next state that takes place when an event occurs?
It’s quite easy to test it yourself. Here’s a minimal REPL example
(require '[statecharts.core :as fsm])
(defn my-condition-fn [state event]
(println "State: " state)
(println "Event: " event)
true)
(def machine
(fsm/machine
{:id :demo
:initial :s1
;; context will be included in `state`
:context {:my-key :my-value}
:states
{:s1 {:on
{:my-transition
[{:target :s2
:guard my-condition-fn
:actions (fn [& _]
(println "transitioned to :s2"))}]}}
:s2 {}}}))
(def s1 (fsm/initialize machine))
;; evals to => {:my-key :my-value, :_state :s1}
(def s2 (fsm/transition machine s1 {:type :my-transition}))
;; avals to => {:my-key :my-value, :_state :s2}
;; Following is printed to REPL:
;; State: {:my-key :my-value, :_state :s1}
;; Event: {:type :my-transition}
;; transitioned to :s2