-
Notifications
You must be signed in to change notification settings - Fork 23
Description
I often tend to put my application state in an all-encompassing one-or-two-level-deep hash-map wrapped in an atom. Let's say that a DOM element :div#a reactively (i.e., via the rx macro) changes its color based on (-> @state :div#b :style :color). Now let's also say that :div#c reactively changes its color based on (-> @state :div#d :style :color). Div A depends on div B, and C on D, but [A and B] do not affect [C and D] at all, and vice versa.
Now suppose that (swap! state assoc-in [:div#b :style :color] :white) is called. Because the value of state is atomically modified, are the colors of divs A and C considered "dirty" and thus the values must be recalculated by calling the functions which rx created for each of them respectively? Or does freactive know that only div B's color was changed and so C's does not need to be recomputed?
This brings me to the question in the title: would cursors be more efficient in this case? Instead of writing code like so:
[:div#a {:style {:color (rx (-> @state :div#b :style :color))}}]
...should I write code like this?:
[:div#a {:style {:color (let [c (cursor state (comp :color :style :div#b)]
(rx @c)
That is, would cursor c only be invalidated if div B's color changed and not on every modification to state?
Thanks for your time!