6

What's the best of following approaches?

Outer subscription, early deref

(defn component [msg]
    [:p msg]))

(let [msg (rf/subscribe [:msg])]
    [component @msg]

Outer subscription, late deref

(defn component [msg]
    [:p @msg]))

(let [msg (rf/subscribe [:msg])]
    [component msg]

Inner subscription, early deref

(defn component []
   (let [msg @(rf/subscribe [:msg])]
      [:p msg])))

Inner subscription, late deref

(defn component []
   (let [msg (rf/subscribe [:msg])]
      [:p @msg])))

When I keep the inner component pure using outer subscription, I can end up with many arguments that need to be passed through deeply nested structure of often unrelated parents. That can easily become a mess.

When I subscribe inside inner component, it becomes impure, losing easy testability.

Also, I wonder if there is an important difference between early and late dereferencing, other than I have to pass reagent/atom when testing the latter.

4

2 に答える 2