Fork me on GitHub
#reagent
<
2018-09-28
>
deadghost11:09:40

when you break down a component do you pass in parameters to the subcomponent or do you have the subcomponent dereference the subscriptions?

tatut12:09:31

I’m guessing you use re-frame (because of the term subscriptions)

tatut12:09:52

I do all my components as pure functions and pass everything in as parameters

miikka13:09:22

We do a mix of both. I don't have a clear answer on which would be better.

valtteri13:09:44

I’ve ended up doing both as well. In my head I call pure components components and ones that subscribe to db I call views. In this parlance views are composed from components and subscriptions.

valtteri13:09:46

Usually I refactor view into a component when I notice that I need the same stuff in some other place.

souenzzo14:09:11

In my utils namespace there is a distinct-by function, a custom version of distinct that applys a f in the values

souenzzo14:09:57

https://gist.github.com/souenzzo/2a2e74d56fc7bd6e7a35977bfb0939b9 It do the same of distinct Or you can do (def distinct-by #(map (comp first val) (group-by %1 %2)))

tatut13:09:15

in Tuck there are only pure functions, no subscriptions or anything like that

Garrett Hopper21:09:36

Can someone give me some feedback on how this could be cleaned up?

(def credentials (r/atom nil))

(def client (ratom/reaction
             (when @credentials
               (create-client @credentials))))

(def data (let [a (r/atom nil)
                b (ratom/reaction
                   (when @client
                     (.then (.query @client)
                            #(reset! a %))))]
            @b
            (ratom/make-reaction
             (fn [] @a)
             :on-dispose #(ratom/dispose! b))))
I have credentials that have to be requested from the server via an API. Once I have those, I can create a client. Once I have that client, I need to make queries which return promises. The problem is, I can't find a clean way to get the response from those promises into a reaction. FYI, I'm using this in a re-frame handler, though I've removed re-frame specific stuff for this question.