Fork me on GitHub

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:

 (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. 🙂