Fork me on GitHub
#re-frame
<
2019-07-18
>
pwojnowski09:07:50

Hi. I'm writing an app usign re-frame and I'm not sure where I should put parts of code. I created a button to load a file using File API. IIUC the button should send event to event handler. The handler should declare what should be done with it - in my case I want to load the file using File API in browser. So then I should create (reg-fx ...) which will actually load the file and then what? Store it directly in app-db? Can I dispatch on-load/on-error events from an effect handler?

oconn11:07:20

For something like this I’ve typically created stateful components that work with the file api in reagent - then when the work was done (create / modify files) I dispatch an event to persist data etc..

pwojnowski12:07:57

Thanks. I'll look at that.

Ahmed Hassan10:07:48

How can we make pessimistic updates in re-frame?

lepistane10:07:45

what's that?

Ahmed Hassan10:07:30

Like change persists in local db after server request is successful.

oconn11:07:54

Have you taken a look at something like https://github.com/Day8/re-frame-http-fx? The approach looks like: 1. Dispatch event that triggers request side-effect (no data changes and on-success & on-failure event handlers are defined) 2. On 2xx response update your db with the server response

oconn11:07:01

I’ve also written a lib that adds a little more state tracking to requests https://github.com/oconn/re-frame-request that you may find interesting.

Ahmed Hassan11:07:44

@U1APR44RE thanks. That helps.

deadghost15:07:20

how are you guys keeping track of http request states?

deadghost15:07:52

for example with http-fx I make a GET request to /api/foos

deadghost15:07:14

and want to show a twirler while it's in progress

danielneal15:07:38

you can put something in the db in the same effect handler, and take it out on success or failure

deadghost15:07:50

yeah that was my thought as well

deadghost15:07:29

I'm thinking under (get-in db [:state :http :foos])

deadghost15:07:36

and give it a :loading value or somesuch

danielneal15:07:44

yeah that would work

mikerod19:07:15

@deadghost I think the re-frame docs have an example like this as well