Fork me on GitHub
#re-frame
<
2021-03-07
>
zendevil07:03:33

I have the following effect:

(reg-fx
 :launch-image-library
 (fn [navigation]
   (launchImageLibrary (clj->js {:mediaType "photo" :quality 0.1})
                       (fn [res]
                         (dispatch [:add-date-time navigation (get (js->clj res) "uri")])
                         ))))
Is there a way that I can make it pure?

zendevil07:03:38

I want to get rid of the dispatch

zendevil08:03:48

is there a way to do that?

Lu09:03:35

well the event gets called in a callback.. not sure you can easily remove it.. if that’s the only place where you do the :add-date-time logic maybe you can just hard code it straight into the callback

p-himik09:03:21

Regardless of the callback - effects are supposed to be impure. IMO the code above is perfectly fine.

Lu09:03:00

Oh yeah that fx is already impure without the dispatch :) so if that’s the concern there’s nothing to add

aaron5123:03:17

What’s a good pattern for “Fire event X after A, B and C are fired asynchronously”? In the browser, we need to load data from several sources, simultaneously, and only render the DOM when the loads are complete.

p-himik00:03:31

Depends on specifics. If A, B, and C just happen once and that's it, then https://github.com/Day8/re-frame-async-flow-fx

mikethompson00:03:44

There is also https://github.com/ingesolvoll/re-chain (although I've not used it)

aaron5106:03:51

Yes, it’s a one-time boot sequence. Thank you for the links 👍