This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-06
Channels
- # announcements (16)
- # aws (9)
- # babashka (76)
- # beginners (92)
- # boot (1)
- # cider (18)
- # clara (7)
- # clj-kondo (26)
- # clojure (104)
- # clojure-europe (4)
- # clojure-nl (11)
- # clojure-spec (11)
- # clojure-survey (101)
- # clojure-uk (35)
- # clojuredesign-podcast (18)
- # clojurescript (8)
- # core-async (29)
- # data-science (1)
- # datomic (13)
- # emacs (4)
- # fulcro (20)
- # graalvm (14)
- # instaparse (2)
- # jobs (1)
- # juxt (6)
- # malli (5)
- # off-topic (30)
- # onyx (3)
- # planck (1)
- # project-updates (7)
- # re-frame (38)
- # reagent (30)
- # reitit (14)
- # remote-jobs (2)
- # shadow-cljs (50)
- # sql (8)
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.
Have you guys tried to loop a event? I need to loop a rest call for each element on a map.
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.
I was thinking in loop in the :http-xhrio
Is it possible?
:http-xhrio
accepts either a map for a single request or a sequence of maps for multiple requests.
Sequence - as in "it should satisfy sequential?
": https://github.com/day8/re-frame-http-fx/blob/master/src/day8/re_frame/http_fx.cljs#L86
thanks, i'll check that
Let me see if i understood: With :http-xhrio
i can send multiple request just passing a map with the requests?
I have my map with multiple customers, and with this guy the http-xhrio will send one request for each one?
[:main {:street "name" :customer ..uuid..} :facturation {:street "name" :customer ..uuid..}]
For exampleThis is a vector with maps inside
Just for one simple request
(rf/reg-event-fx
:customer/save-addresses
(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]}})))
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
.
In :params
right?
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
{:http-xhrio
[{:uri "..."
...}
{:uri "..."
...}
...]}
{:http-xhrio [ {...}
{...}]}
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.
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 https://github.com/status-im/status-react/blob/develop/src/status_im/events.cljs#L489.
(handlers/register-handler-fx
:chat.ui/navigate-to-chat
(fn [cofx [_ chat-id opts]]
(chat/navigate-to-chat cofx chat-id opts)))
https://github.com/ingesolvoll/kee-frame deals with navigation. But I have no idea whether it's compatible with React Native.
Interesting. That lead me to https://github.com/vikeri/re-navigate which looks like a useful reference.
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. https://github.com/day8/re-frame-async-flow-fx