Fork me on GitHub

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


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


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


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


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.


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


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 It do the same of distinct Or you can do (def distinct-by #(map (comp first val) (group-by %1 %2)))


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 %))))]
             (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.