Fork me on GitHub
#clojurescript
<
2022-06-29
>
pinkfrog14:06:22

Hi. I don’t quite get the use of enable-console-print!. The docs says it binds print-fn to console.log. So does that mean, if we do not do that, the (println) messages won’t be shown?

sansarip14:06:00

For example, if you’re developing a web app, print messages will be shown in your REPL, but not in the browser’s devtools console if you don’t enable-console-print!. Regardless you can still print to the console manually by using js/console.log.

pinkfrog14:06:15

What about production release where there is no REPL?

sansarip20:06:42

Basically without a print function set to output to the web/Node console (i.e. console.log), print statements will not print to console 🙅

Sturm12:07:14

@UGC0NEP4Y enable-console-print! is no longer required as of ClojureScript 1.10 https://clojurians-log.clojureverse.org/clojurescript/2018-10-16/1539688185.000100

pinkfrog12:07:35

oops. that’s from an old thread dating backing to 2018.

slimslenderslacks21:06:27

Should clojure.edn/read-string create js/BigInts when the number has an "N" suffix (running on Node.js target)

(type (edn/read-string "1N")) => #object[Number]
Looking at this for integers > (.-MAX_SAFE_INTEGER js/Number) it still produces only Numbers, never BigInts. In clojure, integers with an N" suffix will create clojure.lang.BigInt`s, and I notice that other edn parsers for javascript do the same. But clojurescript itself seems to lose precision for clojure.edn/read-string

slimslenderslacks21:06:14

Printing a js/BigInt is straight forward:

(extend-protocol IPrintWithWriter
  js/BigInt
  (-pr-writer [n writer opts]
    (-write writer (str n "N"))))
But I can't read them back in using read-string (without losing precision anyway)

slimslenderslacks22:06:20

There's a library called edn-data (https://github.com/jorinvo/edn-data). Using this library, which contains a parseEdnString function:

(def parse-edn-string (.-parseEDNString edn-data))                                                                                                      (type (parse-edn-string "1N")) => #object[BigInt]
we'll get a js/BigInt.

ivana22:06:06

After a lot of frustrations finally I got the model how (actually, contrintuitive imho) Compojure calls middlewares, and want to share maybe the only (?) solution worked the way it shoul be 😊

(defroutes app-routes
  (-> public-routes
      (wrap-routes wrap-parse-params-body))

  (-> secured-routes
      (wrap-routes wrap-parse-params-body)
      (wrap-routes wrap-authentication))

  (-> mobile-routes
      (wrap-routes wrap-parse-params-body)
      (wrap-routes wrap-mobile-authentication))

  (-> (route/resources "/")
      (wrap-routes wrap-authentication)) ;; all resources are private for direct access (load from html etc.)!

  (-> (ANY "*" [] {:status 404}) ;; (route/not-found {:status 404}) doesn't call wrap-authentication!
      (wrap-routes wrap-authentication)))

(def handler
  (-> app-routes
      wrap-cookies))
PS yes, I had to wrap them all with wrap-routes and triplicate wrap-parse-params-body etc.