Fork me on GitHub
#re-frame
<
2017-12-20
>
Lachlan Robertson02:12:53

Does anyone know how to get response-headers from http-xhrio?

danielcompton03:12:33

@lachlan737 check the issues, I think that might be there as one

Lachlan Robertson03:12:59

Yeah it is, was just wondering if anyone knew of any workarounds

andrea.crotti11:12:12

I love it when I get errors like

react-with-addons.inc.js:14783 Uncaught TypeError: Cannot read property 'getHostNode' of null
    at Object.getHostNode (VM11514 react-with-addons.inc.js:14783)
    at ReactCompositeComponentWrapper.getHostNode (VM11514 react-with-addons.inc.js:6618)
    at Object.getHostNode (VM11514 react-with-addons.inc.js:14783)
    at Object.updateChildren (VM11514 react-with-addons.inc.js:4611)
    at ReactDOMComponent._reconcilerUpdateChildren (VM11514 react-with-addons.inc.js:12997)
    at ReactDOMComponent._updateChildren (VM11514 react-with-addons.inc.js:13101)
    at ReactDOMComponent.updateChildren (VM11514 react-with-addons.inc.js:13088)
    at ReactDOMComponent._updateDOMChildren (VM11514 react-with-addons.inc.js:8251)
    at ReactDOMComponent.updateComponent (VM11514 react-with-addons.inc.js:8069)
    at ReactDOMComponent.receiveComponent (VM11514 react-with-addons.inc.js:8027)
in the console

vinai12:12:16

For me a manual reload often helps. Somehow it seems the react/dom state gets into a strange place.

andrea.crotti12:12:42

ah well I get this doing a page reload

andrea.crotti12:12:55

if instead I change something and I get figwheel doing the magic

andrea.crotti12:12:09

which is even more weird, but something messed up in the db initialisation maybe

vinai12:12:08

It took me a while (read: weeks) to realize I can also sometimes scroll all the way to the right in the console to see more info. Not always useful but sometimes it helps.

andrea.crotti11:12:31

there is some extra information about the failure related to some internal re-frame stuff

andrea.crotti11:12:42

but it doesn't help much either šŸ˜„

andrea.crotti11:12:02

any debugging tip?

joelsanchez12:12:27

@vinai I solved it in my project, will get the code for you

vinai12:12:55

Nice!, thank you!

vinai12:12:48

It beats filtering all warnings in the console output. Will use it until the PR from Daniel Compton gets merged šŸ‘

joelsanchez12:12:51

Yes, it's a hack. Yes, it's awful. But it works, and it's reliable šŸ˜›

andrea.crotti13:12:44

anyone using re-frame.test ?

andrea.crotti13:12:11

I get quite wildly results if running with test-cljs or by doing cljs-test.run-tests from the repl

jvuillermet15:12:29

when using a signal-fn like here

(fn [query-vec dynamic-vec]
         [(subscribe [:a-sub])
          (subscribe [:b-sub])])
or using the syntax sugar :<-, is it possible and a good idea to pass result of previous signal into the next ? like
:<- [:a]
:<- [:b a]
(fn [[useless-a? b] _]
   

vinai15:12:55

@jvuillermet ...where a would be the value of [:a]?

vinai15:12:26

I don't think that's possible using that form.

vinai15:12:33

This might work?

(fn [query-vec dynamic-vec]
         [(subscribe [:b-sub @(subscribe [:a-sub])])])

vinai15:12:21

Probably it's better to move it into a regular function and call it from the signal-fns

andrea.crotti15:12:40

would be great to be able to visualize all the various dependencies between subs and events

andrea.crotti15:12:53

since they are all data it should be possible, anyone tried that?

andrea.crotti15:12:00

and any idea what this means re-frame: no :fx handler registered for: :http-xhrio ?

jvuillermet15:12:37

@andrea.crotti you are probably missing [day8.re-frame.http-fx] in :require

jvuillermet15:12:59

this will register the effect you need

andrea.crotti15:12:52

uhm odd it's not there in master either though

andrea.crotti15:12:55

and don't get that error there

andrea.crotti15:12:11

that does fixes it though, weird

mikerod15:12:44

@jvuillermet @vinai in that sort of case, I ended up using reg-sub-raw since I thought it was less dirty than doing it in the signal fn (not sure if that is the appropriate use)

(rf/reg-sub-raw
 :do-it
 (fn [_ _]
   (r/reaction
    (let [a @(subscribe [:a-sub])
          b @(subscribe [:b-sub])]
      (do-it a b)))))

mikerod15:12:01

I donā€™t claim to be right, I just hesitated to put it in the signal fn

mikerod15:12:29

Maybe it is not an abuse of it. Perhaps some re-frame prophet on here can say? šŸ˜›

mikerod15:12:53

Iā€™m looking at the impl for the signal-fn in reg-sub and Iā€™m now a bit doubtful that it is safe to deref subscriptions in it

mikerod15:12:02

Which would mean - use reg-sub-raw

mikerod15:12:29

Basically, itā€™s this:

([db query-vec]
         (let [subscriptions (inputs-fn query-vec)
               reaction-id   (atom nil)
               reaction      (make-reaction
                               (fn []
                                 (trace/with-trace {:operation (first-in-vector query-vec)
                                                    :op-type   :sub/run
                                                    :tags      {:query-v    query-vec
                                                                :reaction   @reaction-id}}
                                                   (let [subscription (computation-fn (deref-input-signals subscriptions query-id) query-vec)]
                                                     (trace/merge-trace! {:tags {:value subscription}})
                                                     subscription))))]

           (reset! reaction-id (reagent-id reaction))
           reaction))
* subscriptions (inputs-fn query-vec) - runs the signal fn * The reaction is created later that wraps over that resulting value. So your derefā€™s have already happened and wonā€™t be done within a reactive context. So they wonā€™t respond correctly to change

jvuillermet15:12:12

Both solutions seems complicated and hard to read to me. It feels that if one start going that road, you will end up with event more complex sub and signal-fn. At some point I guess itā€™s better to have a simple fn that do that by taking the whole db or some part

mikerod15:12:44

@jvuillermet taking the whole db may be fine. Can also lead to unnecessary recomputing though potentially

mikerod15:12:02

Also, I have done this pattern you describe due to other subscription doing significant ā€œmaterialized viewā€ work that I wanted to reuse

jvuillermet15:12:03

Itā€™s the first case I encounter since a while where I needed that

jvuillermet15:12:12

Do you need it more frequently ?

mikerod15:12:16

However, I agree that it isnā€™t necessarily great and probably isnā€™t something youā€™d like to see a ton of

mikerod15:12:19

Iā€™ve needed it quite a bit in one current case where I have a lot of configuration driving the UI in terms of which components are shown and their properties. I just end up having to use ā€œidā€ sort of indexing into most subscriptions

mikerod15:12:42

so when most subscriptions need an ā€œidā€ you have to pass the ā€œidā€ along if you have subscriptions using other subscriptions

mikerod15:12:52

not sure it is a great thing, but Iā€™ve had it come up a few time

mikerod15:12:22

well, I guess that is not the case you describe, we are talking about needing the return value of a subscription as an input to another. Iā€™ve had that happen when my ā€œidā€ isnā€™t explicitly passed in, but rather derivedā€¦ Too abstract. This probably doesnā€™t make any sense to someone reading.

mikerod15:12:28

Letā€™s say it this way: Probably most of the time you shouldnā€™t need reg-sub-raw. However, it exists and is described fairly well @ https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md So Iā€™m guessing it comes up in practice for people. šŸ˜›

jvuillermet15:12:48

I think I get it. In my case, a blog can be edited or not based on user type, user-email and some blog props so the ::can-edit? sub take 4 params. When I want to use this sub, I often already have sub for user-type that would be nice to pass to the can-edit?

mikerod15:12:45

Yeah, I was sort of in a similar siutation when I decided to use reg-sub-raw

mikerod15:12:25

You could push the problem to the components/views like:

(let [user-type @(subs [:user-type])
     can-edit? @(subs [:can-edit? user-type <etc>])] <etc>)

mikerod15:12:41

I didnā€™t like that though, I wanted to be able to not keep pushing intermediary results to the view when the view didnā€™t need to know

mikerod15:12:11

So I ended up just making the :can-edit? style one look up its own user-type and that relied on another subscription and thatā€™s where Iā€™d end up at the reg-sub-raw usage

mikerod15:12:17

(using your example roughly)

jvuillermet16:12:26

yes, pretty sure itā€™s the same use case.

mikerod17:12:35

@jvuillermet one thing that I considered at one point is just share common logic via functions instead of have these more complex subscriptions rely on one another. However, the problem then becomes in always keeping things in sync. I think it starts to make the leaf subscription extra complicated are hard to manage

mikerod17:12:17

So you take all the impl from the subscription into a function for reuse that is independent of the subscription

mikerod17:12:38

but then all callers have to know the inputs to give this function. Which can mean you have to change more places when you have to alter how, in this case, the user type is determined.

mikerod17:12:13

Also, it means all that call this function will be recomputing the results independently. With subscriptions that use others as signals, results only computed once then shared