Fork me on GitHub
#re-frame
<
2022-05-23
>
popeye11:05:48

I am working on the reframe and created a component using reagent/create-class and inside :reagent-rendor, I have a condition, which filter the data and those data I am adding to the reframe db atom like below

(defn do-something
   (reagent/create-class
      {:reagent-render 
          (fn [{:keys [data payload status]}])
            (if (= data "something")
            (dispatch [:do-something-else 3]])
            (dispatch [:do-something "riyu"]]))
          }))
Is it right to call dispatch method anywhere? or we should call it always when even occurred If we cannot call dispatch function, How to insert the data in reframe db

p-himik11:05:38

Don't call dispatch in the render function. The right approach is outlined here: https://day8.github.io/re-frame/FAQs/LoadOnMount/

popeye11:05:11

thanks for response @U2FRKM4TW, How can I add the data into db if I want to ?

p-himik11:05:20

Have you read the page that I linked?

popeye11:05:27

yes, But in my scenario, I am designing a pagination, where as I wanted to store each page db value, which I am doing for pagination

p-himik11:05:12

I'm sorry but I have no clue what you mean. I've implemented pagination many times, and it has never required dispatching events from within the render function itself (i.e. not as a reaction to some user input).

😂 1
raymcdermott11:05:51

I have re-frame app using http-xhrio to obtain CSV data from a server. It's all working but I would like to offer the data as a file to download. I was hoping to hand it off to the browser but don't know the mechanisms to achieve that. Can anyone point me in the right direction?

p-himik11:05:08

Not re-frame specific at all. Just create an <a download href="...">...</a> on your page with the right URL.

p-himik11:05:57

If you don't want a link but rather want the download to happen as a reaction to some user's action (which is not a click on a URL), you can use e.g. https://github.com/eligrey/FileSaver.js/

raymcdermott11:05:23

Oh so just magic that up after I have the data back?

raymcdermott11:05:13

I need to send an auth token to the backend so it can't be a simple link ... AFAIK

p-himik11:05:21

Well, you can do it all manually, there's no magic. :) But making it work properly across browsers used to be a pain. Maybe it's not anymore, I haven't checked for a few years.

p-himik11:05:30

What do you mean by "send" in this case?

raymcdermott11:05:55

I mean include as an Authorization Bearer .... header

p-himik11:05:23

Yeah, you have to use a separate AJAX request then, unless that endpoint is the same server and your app and it supports cookies.

raymcdermott11:05:20

it is on the same domain ... a Lambda behind an API GW behind CloudFront. I could change everything to cookies but that feels like a pain now and we want some POSTs via that site too so I'm not so enthusiastic about doing it

raymcdermott11:05:55

I mean I'm in control of everything so I could do the cookies thing but cookies feel yucky if you know what I mean

raymcdermott11:05:09

when I say magic I just meant create it on the back of some event dynamically 🙂

p-himik12:05:22

Actually, no clue what you mean by cookies being yucky. As far as I'm aware, manually storing and providing authorization tokens is much worse in any situation where you could use secure cookies that are specifically designed to be used for authentication.

raymcdermott12:05:09

ok, the integration to authentication service I'm using (OKTA) uses access tokens so that's what I'm using

raymcdermott12:05:56

Looking at the README, he recommends the Content-Disposition header, which I am setting so maybe it's getting lost in the infra

raymcdermott12:05:50

hmmm, no ... it's coming through but is somehow being ignore by the browser

raymcdermott13:05:19

ok, I used saveAs on http-xhrio success. As I guess you know AJAX does not offer a way for the browser to save files directly

👍 1