Fork me on GitHub
#re-frame
<
2018-04-17
>
danielcompton02:04:04

what are you trying to achieve here?

danielcompton02:04:01

I would add a logging statement to the on-dispose for the reaction to check if it is cleaned up

danielcompton02:04:24

But at first glance I think it would be fine

danielcompton02:04:31

Though I don't really understand the wider context here

kenny03:04:28

@danielcompton I'd like to have a reg-sub-computation that takes an output-signal-fn and computation-fn. output-signal-fn is passed the re-frame DB or a vector (or single obj) of signals and the event-vec and is expected to return a Reaction R. I want to run computation-fn on the value of R only when its value changes. Essentially the below code (the excerpt is take from our existing codebase so it's not in its actual form)

(defn reg-sub-computation
  [query-id signals output-signal-fn computation-fn]
  (reg-sub-raw
    query-id
    (fn [*rf-db event-vec]
      (ratom/make-reaction
        (fn []
          (computation-fn @(ratom/make-reaction
                             (fn []
                               (let [input-signals (normalize-signals signals event-vec)]
                                 @(output-signal-fn (if signals
                                                      (if (sequential? input-signals)
                                                        (mapv deref input-signals)
                                                        @input-signals)
                                                      (deref *rf-db))
                                                    event-vec))))
                          event-vec))))))

kenny03:04:35

I also have a function called reg-sub-raw-wrap which I tend to use more than that one because it tends to be a bit more clear, albeit more verbose. That function simply does this:

(defn reg-sub-raw-wrap
  "Like [[reg-sub-raw]] except wraps `handler-fn` in a reaction."
  ([query-id opts handler-fn]
   (reg-sub-raw
     query-id opts
     (fn [*rf-db event]
       (ratom/make-reaction (fn [] (handler-fn *rf-db event)))))))

mikethompson04:04:39

@kenny that is making my head hurt a bit.

mikethompson04:04:58

Frankly, I'm not sure I'm following

mikethompson04:04:40

Is it possible to give a more "wordy" explanation. I feel like you might be on the wrong path but I'm struggling to figure out where you want to get to .

kenny04:04:16

There is a bit of functionality that isn’t possible with the default reg-sub that that function was trying to solve. I also agree — it is a little mind bending — and I actually use the reg-sub-raw-wrap in favor of it because it reads a lot cleaner. There may be an abstraction hiding underneath and I don’t think that function is it. It would probably help to have a concrete example problem.

alex-dixon07:04:02

Sounds like you want a change event to propagate if and only if there’s a value that’s different? To avoid unnecessary, potentially expensive calculations?

kenny16:04:45

Right. Not clear exactly how something like that fits into the re-frame API though.

sveri14:04:01

Hi, Looking through examples I have a question about views. All I see are three different kinds:

; returning a fn
(defn view []
  (fn []
    (let [:baz (rf/subs [:ev])]
      [:div ...])))

;the let form first
(defn view []
  (let [:baz (rf/subs [:ev])]
    (fn []
      [:div ...])))

; just returning a vec
(defn view []
  [:div ...])
Which is the correct one to use?

danielneal14:04:16

In most simple cases you can use the third one now

danielneal14:04:49

because subscriptions are cached, you can call (subscribe [:subscription ...]) wihtout fear

danielneal14:04:12

I think there's a discussino about it somewhere

sveri14:04:13

@danieleneal Thanks, that was a very helpful link, exactly what I was looking for and its great they introduced these changes. @plexus Very well written article, thank you for that.

lwhorton16:04:07

does reframe offer an enrich-fx as opposed to just enrich?

lwhorton16:04:27

i was thinking this:

(->interceptor
    :id :enrich-fx
    :after (fn enrich-after-fx [context]
             (assoc context :effects (merge (:effects context)
                                            (f (:coeffects context))))))
but i want to make sure im not clobbering the ins/outs

mikethompson22:04:31

@lwhorton nothing like that in the API