Fork me on GitHub

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?


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..


Thanks. I'll look at that.

Ahmed Hassan10:07:48

How can we make pessimistic updates in re-frame?


what's that?

Ahmed Hassan10:07:30

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


Have you taken a look at something like 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


I’ve also written a lib that adds a little more state tracking to requests that you may find interesting.

Ahmed Hassan11:07:44

@U1APR44RE thanks. That helps.


how are you guys keeping track of http request states?


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


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


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


yeah that was my thought as well


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


and give it a :loading value or somesuch


yeah that would work


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