Fork me on GitHub
#clojurescript
<
2019-11-08
>
lilactown06:11:56

I'm reflecting on how fundamental namespaces are in ClojureScript

lilactown06:11:17

I've been digging into how hot reloading is implemented in webpack et al. and apparently when you edit a file, they have to reload every dependent module (file). because each module actually closes over the exact instance of the module that was loaded when it was instantiated

lilactown06:11:26

in shadow-cljs and figwheel, we just refer to the global variable which corresponds to that namespace because it's guaranteed to be unique

thheller08:11:01

mindblowing how something simple as namespaces can be so effective right? 😛

jaihindhreddy09:11:40

They is that effective because they are so simple 😛

Ramon Rios09:11:56

Hello, have you guys tried to put a dynamic id into a [:div] or other object?

Lu09:11:49

Like looping over some ids and assigning them to the element?

Ramon Rios09:11:11

I have a form for a address

Ramon Rios09:11:31

But i need to reuse it sometimes on the same part of the code

Ramon Rios09:11:58

"main address" "facturation Address"

Ramon Rios09:11:25

And i would like to render a different id for each one elements

Ramon Rios09:11:02

What i was trying to is to put an argument on the function but it did not work as i expected.

papachan11:11:28

Can i see your code maybe i can help you.

ivana09:11:22

Hello. Can I ask about react native here or there is another live channel for it?

thheller09:11:20

@ivana there is #cljsrn

ivana09:11:23

Yes, but it seems to be rare visited...

sova-soars-the-sora14:11:16

from a new user perspective it would be very nice to have a [js] one half [equiv cljs other half] page for some frameworks

sova-soars-the-sora14:11:38

there's always stuff i want to translate into cljs without much of an idea on how to go about it ;x

Mario C.15:11:30

This is a long shot but has anyone ever seen this error? Uncaught ReferenceError: currentPriorityLevel is not defined. I am using Reagent/Re-Frame. This is happening when trying to add the main app onto the <div id="app"/> root.

Mario C.15:11:54

(defn fetch-loan-button
  [loan-id]
  [:button
   {:on-click (fn [e]
                (.preventDefault e)
                (rf/dispatch [:fetch-loan loan-id]))}
   "Fetch Loan"])

(defn panel
  []
  (let [_ (rf/subscribe [:db])]
    [:div
     [:input {:type "text"}]
     [fetch-loan-button "123456789"]]))

Mario C.15:11:01

This is the panel I am trying to add

Mario C.15:11:39

This is what core.cljs looks like

(defn mount-root []
  (reagent/render [fp/panel]
                  (.getElementById js/document "app")))

(defn ^:export init []
  (re-frame/dispatch-sync [:initialize-db])
  (dev-setup)
  (mount-root))

Ramon Rios15:11:34

Usually it means that currentPriorityLevel is below of the function that is calling it

Mario C.15:11:27

What does that generally mean?

Ramon Rios15:11:50

(defn foo2
  [foo])

(defn foo
  [:h1 "hello"])

Ramon Rios15:11:40

You're calling foobut foo is after foo2 wich is calling foo

Mario C.15:11:23

Hmm that doesn't seem to be the case here though

Mario C.15:11:57

I can do this and it still happens

(defn mount-root []
  (reagent/render [:h1 "hello"] #_[fp/panel]
                  (.getElementById js/document "app")))

Mario C.16:11:53

Ah I think i know what it is

Mario C.17:11:09

@UNZALKY4V Any other reason this could be happening?

Mario C.17:11:03

I am also getting ImmediatePriority is not defined

Mario C.19:11:21

It ended up being dependency issues

coder4633417:11:33

Hi! What's the best way to throw an error if I manage to get myself into an infinite loop/recur? Does a timeout macro or something like that exist?

mruzekw17:11:40

Does anyone know of a cljs function for creating a x-www-form-urlencoded payload?

darwin17:11:20

roll your own, IMO it is not worth pulling in a library for simple js/encodeURIComponent usage

👍 4
mruzekw17:11:31

I guess cljs-http.client/generate-query-string would work?

mruzekw17:11:45

Looks like there’s also cemerick.url/map->query for anyone who’s curious (but the repo is archived on GH)

mruzekw17:11:37

And no.en.core/format-query-params

andy.fingerhut17:11:08

@publicz I am not aware of such a timeout macro in Clojure's core library, but wouldn't be surprised if there was a library somewhere that had one. If you want to stop a Java thread that is an infinite loop/recur, one way would be to call the Thread.stop method on the misbehaving thread from a different monitoring thread, but there are serious warnings about that being unsafe for arbitrary JVM code, e.g. here: https://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html . If you somehow knew the thread was executing 'safe to be stopped' code, it might be safe.

coder4633417:11:08

Hi Andy, thanks for your reply! In this case I'm using Javascript, and it's freeezing up my browser so these bugs are a pain in the neck to debug. It would be most useful during dev/testing where I don't have proper input validation put in yet. I mean I can make a counter or timer to exit the loop, but I was curious if there are some libraries / best practices / macros there already.

andy.fingerhut17:11:36

Ugh, sorry, I forgot I was typing in the #clojurescript channel.

coder4633418:11:05

No worries, was still interesting to read 🙂 I do some java dev in my day job, so I could relate

borkdude20:11:48

should a CLJS linter accept (fn [e] e.message) as an alternative to (fn [e] (.-message e))? I really don't know the answer, so I'll let CLJS experts be the judge

borkdude20:11:19

it currently says: I don't know what e.message is. It could say: use (.-message e) but I don't know if that's always the right answer in every possible case 🙂

lilactown20:11:46

I would special case things in the js ns since it’s probably fairly prevalent when access things on document or window

borkdude20:11:05

yeah, since that's "namespaced" it always works

lilactown20:11:04

you would want to check whether e.message is being used as an accessor or as a method call

lilactown20:11:37

(e.message "foo") vs bare (prn e.message)

borkdude20:11:52

that's not always possible, e.g. (map e.fn xs)

lilactown20:11:24

in that case it would still be correct to access it as a property rather than a method call

borkdude20:11:41

then why would I want to check this at all?

lilactown20:11:02

(map (.-fn e) xs) is correct. (map (.fn e) xs) is not (it would immediately invoke (.fn e)

borkdude20:11:36

but maybe (.fn e) returns a function, so that <could/> be correct

lilactown20:11:52

it’s only the case where e.fn is being called immediately as a method that you would rewrite it to (.fn e) instead

lilactown20:11:03

then the original would be (map (e.fn) xs)

lilactown20:11:48

I can’t think of any other case where e.fn would be invoked immediately as a method other than it being in the first place of a list, from a syntax POV

lilactown20:11:14

but I am one voice. i’ll let others chime in now. 😄

sova-soars-the-sora21:11:33

@mario.cordova.862 did you figure it out? calling [function] or [(function)] ?

Mario C.21:11:34

@sova Yea it was a dependency issue