fulcro

2025-08-07T15:26:13.867969Z

I know everyone has moved on to statecharts, but I'm still chugging along with UISM and have style question. When you are transitioning to a new state and want to take an action at the same time, which of these would people think is more idiomatic? I'm asking because I'm giving a fulcro demo with UISM at the local clojure meetup and couldn't decide which style to show. sending an event to the new state and doing the transition work in new state - there's more code here but I feel a little better about it

{:initial
 {::uism/events
  {::uism/started {::uism/handler
                   (fn [{::uism/keys [event-data asm-id] :as env}]
                     (-> env
                         (uism/activate :state/loading)
                         (uism/trigger asm-id :event/load event-data)))}}}

 :state/loading
 {::uism/events
  {:event/load
   {::uism/handler
    (fn [{::uism/keys [event-data] :as env}]
      (-> env
          (uism/load (:ident event-data) MyComponent {::uism/ok-event :event/loaded})))}

   :event/loaded
   {::uism/target-state :state/ready}}}

 :state/ready {}}
doing the transition work in at the same state that does the transition - the code is cleaner for for sure
{:initial
 {::uism/events
  {::uism/started {::uism/handler
                   (fn [{::uism/keys [event-data] :as env}]
                     (-> env
                         (uism/activate :state/loading)
                         (uism/load (:ident event-data) MyComponent {::uism/ok-event :event/loaded})))}}}

 :state/loading
 {::uism/events
  {:event/loaded
   {::uism/target-state :state/ready}}}

 :state/ready {}}

2025-08-07T15:27:49.414379Z

And, yes - in this case a simple load marker is probably better, but this is a simplified case for example. Imagine a little more work happening

michaelwhitford 2025-08-07T15:43:21.819229Z

I personally prefer the first one, it is only a few more lines but it shows clearly the transition as a separate thing.

2025-08-07T15:49:24.422059Z

It kind of makes me wonder why there isn't an optional arg on uism/activate for the transition event:

(uism/activate env :state/foo :event/bar)