This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-13
Channels
- # announcements (1)
- # babashka (2)
- # biff (10)
- # cider (11)
- # clara (17)
- # clerk (10)
- # clojure (21)
- # clojure-berlin (4)
- # clojure-brasil (1)
- # clojure-europe (32)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-uk (10)
- # cursive (2)
- # data-science (11)
- # datomic (10)
- # emacs (8)
- # events (7)
- # fulcro (29)
- # gratitude (2)
- # honeysql (21)
- # hyperfiddle (7)
- # lsp (2)
- # malli (4)
- # polylith (4)
- # reitit (8)
- # releases (1)
- # shadow-cljs (15)
- # squint (3)
- # xtdb (5)
Is it intentional that set-map-ops return a vector?
(defn set-map-ops
"Returns an operation that will set all of the k-v pairs from `m` into the
data model."
[m]
[{:op :assign
:data m}])
assign and delete in the same ns return a mappossibly, I was looking for a way to clear the state of the chart
No, I think that op is half-baked…it should be building a vector of assign ops, one per k-v pair 😕
the :assign op
(defmethod run-flat-op :assign [all-data {:keys [data]}]
(reduce-kv
(fn [acc path value]
(cond
(= :ROOT path) value
(keyword? path) (assoc acc path value)
(and (vector? path) (= :ROOT (first path))) (assoc-in acc (rest path) value)
(vector? path) (assoc-in acc path value)
:else acc))
all-data
data))
(defmethod run-fulcro-data-op! :assign [app processing-env {:keys [data]}]
(let [session-id (senv/session-id processing-env)
local-data (get-in @(state-atom app) (local-data-path session-id))
aliases (get local-data :fulcro/aliases)]
(swap! (state-atom app)
(fn [all-data]
(reduce-kv
(fn assign* [acc path value]
(let [path (resolve-actors-in-path local-data path)]
(cond
(= :ROOT path) (assoc-in acc (local-data-path session-id) value)
(and (sequential? path) (#{:fulcro/state :fulcro/state-map} (first path))) (assoc-in acc (rest path) value)
(and (keyword? path) (contains? aliases path)) (assign* acc (get aliases path) value)
(keyword? path) (assoc-in acc (local-data-path session-id path) value)
(and (vector? path) (= :ROOT (first path))) (assoc-in acc (into (local-data-path session-id) (rest path)) value)
(vector? path) (assoc-in acc (into (local-data-path session-id) path) value)
:else acc)))
all-data
data)))))
I think I'm using the fulcro one then
so if I use :ROOT as path and give it my initial data as value I will have a clear state
Ah, the difference is that assign
has an API like assoc
, and set-map-ops
has an API more like merge
….but you are right that there is no need for the vector there
how do you deal with statechart events that require a route change in the UI? for instance I have:
(on :review :state/closed
(script-fn [_ {:keys [new-topic-id]}]
(when new-topic-id
(comp/transact! app [(mutations/route-to-topic {:subject-id new-topic-id})]))))
so my current solution is to call the mutation to route with transact!I personally make my own state that forces the route called rstate
…didn’t I talk about this already?
yeah you did
rstate stands for routing-state?
right so you call change-route! in the script-fn (which is actually what my mutation does so I could just get rid of it)
Here’s my thinking: Routing is a globally stateful thing. When you’re on a route that is a singular fact in the entire system. My statechart code relies on the UI being in a particular condition when I’m in a state, then it should be in control of that
The only caveat is if you use allow route change on targets in DR…then you can break things because the statechart will move to the state, but the route won’t
which is why I’d suggest moving away from DR features like that (side effects on will-enter and denying routing via allow-route-change?). Move all of that logic into the chart, where it belongs and isn’t peppered all over the place 😄
When I wrote DR I was trying to meet immediate needs of users who wanted what it does. But I never much cared for the way it pushes you to program. I’m very rapidly moving towards having statecharts be the primary logic artifacts in my UI. They compose, you can invoke them, they can have parallel regions, etc.