Fork me on GitHub
#re-frame
<
2020-06-22
>
Spaceman01:06:14

I call a js function using component-did-mount\:

(def load-map (with-meta identity
                {:component-did-mount
                 loadMap}))

(defn map []
    [load-map [:div {:id "this-div"} "hello"]]
)

Spaceman01:06:09

But only want to call loadMap once per page load. :on-mount doesn't work

Spaceman01:06:35

loadMap can't be called directly on the page load in an effects handler because this-div needs to be mounted before loadMap is called because loadMap accesses the div using the this-div id

Spaceman01:06:19

the error is:

You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.
cj @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k__MfQzY&callback=initMap:138
ij @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k__MfQzY&callback=initMap:135
google.maps.Load @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap:14
(anonymous) @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap:227
(anonymous) @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap:227

mikethompson01:06:50

@pshar10 I can see that Thomas Heller has given you a dressing down in another channel and has threatened to start ignoring you. I can assure you, I have been ignoring you in this channel for well over two weeks. Your questions and approach is aggressive and demanding, and you don't seem to do the slightest bit of research before demanding that volunteers on this and other channels help you.

21
mikethompson01:06:18

There is plenty of material out there which covers integrating Reagent with stuff like Google maps

mikethompson01:06:30

It would take you 1 min of googling to figure it out. But instead you cross post this same question to three channels and then aggressively demand volunteer answers in a way which has certainly annoyed Thomas and I can assure you as annoyed me.

mikethompson01:06:42

The stupid thing is that there is a page on EXACTLY this subject in the re-frame docs. Just do some research. Don't demand anything from anyone here. And learn to ask good questions.

kenny16:06:35

Can someone point me to the place in the re-frame docs that talks about creating events that represent user intent, not generic code ops. I cannot seem to find the appropriate section. For example, to avoid doing something like the below. We're bringing some new folk on and one has started doing something like this 🙂

(rf/reg-event-db 
  ::assoc 
  (fn [db [_ path val]]
    (assoc-in db path val)))

p-himik17:06:17

Can't find anything about events but there's this about subs: http://day8.github.io/re-frame/correcting-a-wrong/#a-final-faq

kenny17:06:04

Ah yes, that was actually the exact section I had in my memory!

p-himik17:06:42

But notice that it talks about keeping the views simple. So I'd say that the same applies to events. Also, it means that it's perfectly fine to have such subs/events as e.g. signal subs and events that are used only by the :dispatch effect. Just don't use them in views.

p-himik17:06:49

I would advise to just give the new folk the link to the documentation and ask them to read through it. :) It's a good read, and while not everything will be remembered right away, a certain familiarity with the concepts will be developed.

kenny17:06:28

Oh yes, I have. They are also just learning Clojure so I'm sure lots doesn't sink in on the first read 🙂

p-himik17:06:52

Oh, actually David did answer your question in the main channel, oops. There's even an additional link.

6
David Pham16:06:52

I have this one for subscription, but I guess it has the same intent?

David Pham17:06:07

At the bottom, it speaks about generic path and DRY

David Pham17:06:13

Does it answer your question?

kenny17:06:26

Yes, that bottom faq section has the exact piece I was looking for!

David Pham17:06:49

Otherwise there is this one from purely functional

kenny17:06:41

These guides are excellent. Will send these along as well. Thank you.

Jakob Durstberger08:06:32

Great stuff, thanks