Fork me on GitHub

Sometimes I see people using subscribe inside :on-click or other JS event handlers, and I sometimes catch myself doing the same. But, if I'm understanding the code correctly, it creates a memory leak and gradual performance degradation in the same way using subscribe in a re-frame event handler does. I couldn't find any mentions of it in the docs. Am I blind, or should it be added there?


Yeah, i agree. It should be documented


I opened an issue so this doesn't get lost, will write up a new FAQ entry in the docs for it if nobody else wants to.

Ramon Rios16:01:06

Have you guys tried to loop a event? I need to loop a rest call for each element on a map.


You mean something like

(doseq [[k v] m]
  (dispatch [:ev k v]))


Or multiple :http-xhrio inside a single event handler?

Ramon Rios16:01:13

The first option


It will work, but it's not a great solution if you run the code in response to some user action. You should put the loop inside the event handler.

Ramon Rios16:01:03

I was thinking in loop in the :http-xhrio

Ramon Rios16:01:15

Is it possible?


:http-xhrio accepts either a map for a single request or a sequence of maps for multiple requests.

Ramon Rios16:01:04

thanks, i'll check that

Ramon Rios16:01:31

Let me see if i understood: With :http-xhrio i can send multiple request just passing a map with the requests?

Ramon Rios16:01:02

I have my map with multiple customers, and with this guy the http-xhrio will send one request for each one?


By just passing a vector of maps.

Ramon Rios16:01:06

[:main {:street "name" :customer ..uuid..} :facturation {:street "name" :customer ..uuid..}]
For example


What is this?

Ramon Rios16:01:23

This is a vector with maps inside


Have you used :http-xhrio before?

Ramon Rios16:01:34

Just for one simple request

Ramon Rios16:01:29

 (fn [{:keys [db]} [_ cust-id]]
   (let [addresses (setting-address-id (d/addresses db) cust-id)]
     {:http-xhrio {:uri "api/addresses"
                   :method :post
                   :format ajax/json-request
                   :response-format ajax/json-response
                   :params addresses
                   :on-success [:customer/addresses-success]
                   :on-failure [:customer/addresses-failure]}})))

Ramon Rios16:01:37

This is the one that i'm doing now


That's not a vector of maps. That's a heterogenious vector. You pass to :http-xhrio a single map that describes how to make this XHR, right? Now create a map for each request. Put all these maps in a vector. And pass that vector into :http-xhrio.

Ramon Rios16:01:07

In :params right?


In :http-xhrio.


Every map passed to :http-xhrio is a single request. Everything within that map is relevant only for that request.


You should end up with something like

 [{:uri "..."
  {:uri "..."

Ramon Rios16:01:19

{:http-xhrio [ {...}

Ramon Rios16:01:37

I got now, many thanks

ūüĎć 4
Ramon Rios17:01:00

I created a def with the request and i'm going to see a reduce or something like that for create new lists with the multiple params that will be sent on these requests.

Eric Ihli20:01:45

Anyone know of any good resources on a good way to do navigation in re-frame? How to integrate the event/effect stuff with something like React Native Navigation? I'm currently doing this.

(this-as this <...> {:on-press (fn [] (. (.. this -props -navigation) navigate "edit"))} <...>)
But I could see it being "better" to do something like this.
{:on-press (fn [] (rf/dispatch [:navigate "edit"]))}
It looks like the Status project is doing the latter
 (fn [cofx [_ chat-id opts]]
   (chat/navigate-to-chat cofx chat-id opts)))

p-himik20:01:35 deals with navigation. But I have no idea whether it's compatible with React Native.

Eric Ihli22:01:44

Interesting. That lead me to which looks like a useful reference.

AJ Jaro13:01:19

I’m using Day8 Async Flow to dispatch events when navigation changes occur. I store the route handler information and then check for matching routes to dispatch a set of events for.