Fork me on GitHub
#re-frame
<
2016-09-06
>
shaun-mahood00:09:41

Does it matter at all if all 4 API calls return before you display anything, and is there any order that matters? My assumption is that you need them all back before rendering and that order doesn’t matter, is that correct?

dpsutton00:09:55

i'm ok with them populating as they come back

dpsutton00:09:09

or populating when all complete

shaun-mahood00:09:23

Ok, that should make it a little easier if it doesn’t matter.

shaun-mahood00:09:34

I don’t think there are any real issues doing multiple dispatch from one event - if order mattered you might find https://github.com/Day8/re-frame-async-flow-fx useful, but otherwise I think it should be pretty safe to do them all at once.

dpsutton00:09:04

so just generate 4 events from the ui?

dpsutton00:09:18

when i click load invoices it knows that it takes 4 things to complete that?

shaun-mahood00:09:01

Yeah, I would set it up your button would fire off the load-invoices event, and that would then fire off the API calls and whatever else is needed.

shaun-mahood00:09:27

Might not need that extra level of indirection though.

dpsutton00:09:35

wait are you saying to dispatch from the event handler for load invoices?

dpsutton00:09:23

ui => dispatch [:load-invoice num]; (reg-event-fx :load-invoices (doall (dispatch [api1]) (dispatch [api2])...))?

shaun-mahood00:09:39

Most likely you want to use either effectful handlers or the idea from https://github.com/Day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md

shaun-mahood00:09:43

You could probably do it all from a single -fx handler, some of my gut feel for this is still stuck in the past as I did a lot of DB work the old way and my mindset still hasn’t converted. Do what feels best to you, I doubt you’ll go too far wrong.

superstructor00:09:44

@dpsutton we do e.g.

(reg-event-fx :load-lots-of-foo (fn [{:keys [db]} _] {:http-xhio [{:method :get :uri “a” :on-success [:a-success]} {:method :get :uri “b” :on-success [:b-success]}]}))

dpsutton00:09:17

Oh. Didn't know it worked like that. Nice

dpsutton00:09:24

Thanks. That's exactly what I was looking for

superstructor00:09:43

:http-xhrio from https://github.com/Day8/re-frame-http-fx expects either a map, or a seq of maps.

superstructor00:09:31

if its a seq, it just doseq over all the maps calling the effect for each map.

superstructor00:09:25

I need to get around to doing some pull requests for some bugs in :http-xhrio that we found and fixed in our fork.

superstructor00:09:45

But should get you started 🙂

mikethompson01:09:17

We haven't used re-frame-http-fx much in practice, we did it more as a living example (in contrast we use re-frame-async-flow lots). @yogthos said he had a problem with re-frame-http-fx also .... so very keen to get any rough edges knocked off.

yogthos01:09:20

Yeah, I meant to look more into that, just haven't had the chance

superstructor03:09:04

I think the main issue we had was with not getting a response body due to missing :response-format on the xhrio options so we provide a custom response format fn. Will look at the code later today and see if there is anything useful to push upstream @mikethompson

tom20:09:59

I want to use a third form component that uses ':should-component-update', and return false to skip rendering. In order to determine if false should be returned, I need to compare if one prop has changed compared to a value in 'db'. But as far as I can tell the db value is not something I can access from that lifecycle method. Is that correct?

superstructor21:09:17

@tom use a subscription ?

superstructor21:09:40

@tom e.g.

(defn foo []
  (let [db-value (subscribe [:the-subscription])]
  (reagent/create-class
    {:display-name “Foo”
     :should-component-update (fn [] (if (= … db-value) …

tom21:09:52

I was thinking about that. I just don't know if that will trigger a re-render when the value is updated. If db-value is "A" and then the prop for it is also "A" then of course I can return false. But if there's a change to "B" then it allows a render. Which would include updating db-value which might trigger another render?

tom21:09:13

The situation is that this is to allow use from a larger JSX program, so the complexity is blinding at times haha