Possibly a newbie question here.

Suppose, I have 

(def state (reagent/atom {:a 1 :b 2 :c 3})

An app logic states that a component should become (and remain) visible 
only if :b or :c have changed. Initial state of the component is hidden.
Is there a pattern for dealing with that in bare reagent? (note that I 
don't use re-frame)

My first stab was to introduce a ratom flag and update it whenever keys are 

(def changed? (reagent/atom false))
(defn toggle-changed [] (reset! changed? true))

(def b-stream (reaction (:b @state))
(def c-stream (reaction (:c @state))

(add-watch b-stream toggle-changed)
(add-watch c-stream toggle-changed)

but this doesn't work with reactions. If I pass `state` to `add-watch`, 
then it would work, but I should track changes of keys and values by hand.

Even if it would work, it feels very clunky and in un-clojure way. The 
problem is that every `reaction` or `reagent/track` example uses derefed 
value in a component, while in my case I need only changed event.

You received this message because you are subscribed to the Google Groups 
"Reagent-Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reagent-project+unsubscr...@googlegroups.com.
To post to this group, send email to reagent-project@googlegroups.com.
Visit this group at https://groups.google.com/group/reagent-project.
For more options, visit https://groups.google.com/d/optout.

Reply via email to