This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-01
Channels
- # beginners (15)
- # boot (3)
- # cider (10)
- # clara (2)
- # cljs-dev (19)
- # clojure (31)
- # clojure-uk (9)
- # clojurescript (60)
- # core-async (1)
- # datomic (10)
- # docs (4)
- # fulcro (5)
- # hoplon (33)
- # juxt (1)
- # luminus (1)
- # off-topic (3)
- # om (20)
- # parinfer (2)
- # portkey (61)
- # re-frame (6)
- # reagent (39)
- # shadow-cljs (18)
- # spacemacs (4)
- # specter (8)
Is it fine to update state inside an event handler based on another state value or would that be "impure"? Basically, I want to replace a value with another one from the app state. Here's an example:
(re-frame/reg-event-db
:save-client
(fn [db [_ client]]
(let [id (key client)]
(assoc-in db [:clients id] (:editing-client db))))) ;; I figure out the correct way to update. This is more of an "architectural question".
@robin896 that's fine, you get given an entire app-db as input state as well as your params
As you mentioned, it does mean that the event on it's own isn't quite enough to understand what will happen
but passing all the state you would need into the view, then through the event, then back into the event handler will get old very fast
My rule of thumb is to go with what feels more natural for the data. If the data is being edited/displayed in the UI, then passing it through as an event is ok, but if it's more of an implicit state of your app then referencing it from app-db is ok
@danielcompton Ok, thank you. That's exactly what I thought. 🙂