Fork me on GitHub
#clojurescript
<
2022-05-02
>
mozinator205:05:02

For development purposes I think it would be great if the serversideprops function emitted to nextjs would interface with the local nrepl process and invokes the jvm based version of the server side props function. Because it's nice to at least have repl based development for the server side part

1
huygn07:05:15

I https://github.com/huygn/remix-cljs next-cljs to add basic Remix support (page & loader, can easily add action .etc), but will needs to move away from :npm-module target as it's quite deprecated

😎 1
thheller07:05:48

:npm-module is not deprecated. it'll stay as is. just seems like the newer :esm should be used given that all remix/next examples use ESM code

huygn07:05:38

agree esm is the way to go, just that current :esm requires exports to be pre-defined which I think is a bit verbose, would be great to have per-fn :export like in :npm-module as it fits nicely with remix/next page files as they needs certain exports. I will try using custom target to see how it go thinking-face

carlos antonio neira bustos13:05:33

I'm using re-frame-http-fx but I don't seem to find where to sent the Content-Type header on the request, according to the docs using request-format to json-response should do it, but checking the request it still appears as Content-Type: application/x-www-form-urlencoded;charset=utf-8

mikethompson13:05:51

The code in this realworld implementation should provide answers: https://github.com/jacekschae/conduit/blob/master/src/conduit/events.cljs#L192-L202

👍 1
carlos antonio neira bustos14:05:27

I tried :headers {"Content-Type" "application/json" }

Old account17:05:28

Hello! I wonder if there is a lib already that allows adding <clojureScript></sclojureScript> or <script type="text/clojurescript"> tags directly to HTML?

Old account17:05:26

Borkdude just keeps creating :star-struck:

Quentin Le Guennec18:05:30

Hello, I got an exception trying to print a clojurescript value with either js/console.log or info from timbre, which I cannot easily debug. Is this a known issue and is there an easy way to get around it? Any clue would help.

p-himik18:05:25

I haven't stumbled upon such issues before. If you can't figure it out, try creating a minimal reproducible example. Apart from letting other people try to figure out what's going on, it may improve your own understanding as well.

Quentin Le Guennec18:05:28

Ok, I will try to do that.

Quentin Le Guennec18:05:47

Forgot to mention, it only happens in a production build, not in dev.

p-himik18:05:52

Ah, fun stuff. Probably forgotten externs somewhere.

Quentin Le Guennec18:05:45

eh I really don't know how I could debug this. I can't print it, I can't postmortem it either since it's a production build and I can't connect cider to it. It sounds like an extern issue somewhere, but shadow-cljs isn't giving me any warning.

thheller18:05:20

well, what is the exception?

p-himik18:05:24

There are instances where none of the build tools help. E.g. when you do stuff like (let [x (first ^js some-js-array)] ...).

thheller18:05:03

externs issues are easy to confirm by just using shadow-cljs release app --pseudo-names

thheller18:05:11

if the error disappears it is externs related

thheller18:05:32

if you still get the error, it should be much more legible as well

Quentin Le Guennec18:05:20

@U05224H0W well hmm... it happens in a fulcro error handler so it recursively throws, so the error is a maximum stack size exceded

p-himik18:05:37

You can set a breakpoint there in your browser.

thheller18:05:58

best way to debug is most definitely with pseudo names

thheller18:05:27

well, if it still happens at least. if its gone it gets harder 😉

Quentin Le Guennec18:05:24

--pseudo-names doesn't fix the issue. Can I then assume it's not a extern issue?

thheller18:05:00

no, just the code should be easier to debug

thheller18:05:20

but it does rule out some externs issues yes. just not all.

Carlo23:05:43

I think I still need some help with this kind of function:

(defn obj->clj [obj]
  (if (.isObject js/goog obj)
    (-> (fn [result key]
          (let [v (goog.object/get obj key)]
            (if (= "function" (goog/typeOf v))
              result
              (assoc result key (obj->clj v)))))
        (reduce {} ^js/Array (.getKeys goog/object obj)))
    obj))
Even after importing (:require [goog] [goog.object] in my namespace, when I evaluate (obj->clj js/navigator) I just get :repl/exception back, and I'm not sure how to progress. Moreover, I'm not sure why I can use both js/goog suggesting that goog is a global object, and goog/typeOf, suggesting that goog is a namespace.

timothypratley23:05:49

This seems to do something:

(ns my.ns (:require [goog :as g] [goog.object :as o]))

(defn obj->clj
  ([obj] (obj->clj obj #{}))
  ([obj seen]
   (if (and obj (g/isObject obj)
            (not (contains? seen obj)))
     (-> (fn [acc k]
           (let [v (o/get obj k)]
             (if (= "function" (g/typeOf v))
               acc
               (assoc acc k (obj->clj v (conj seen obj))))))
         (reduce {} (o/getKeys obj)))
     obj)))
probably not exactly what you want... one problem is that js/navigator is self-referencing (so I introduced a seen set). Anyhow HTH 🙂

timothypratley23:05:21

https://clojurescript.org/reference/google-closure-library#using-google-closure-directly explains usage of goog.object FWIW my guess is that if you us the js/goog style with advanced compilation it will fail, as the name would get munged... but I haven't tested that. The reason it "works" at all is just because they happen to overlap in your environment, but you shouldn't rely on that IMO.

timothypratley23:05:47

You might also find the cljs-bean library interesting

Carlo23:05:19

Thank you very much @U06S1EJPL! In the meantime I had hardcoded a depth limit to avoid the self-reference, but your solution is better! I'll check cljs-bean 🙏

😎 1