Fork me on GitHub
#nbb
<
2023-10-11
>
sher07:10:19

Just submitted a fastify example PR, please take a look https://github.com/babashka/nbb/pull/339

sher07:10:23

Will continue to work on this example further, hopefully to a production ready web service that can be deployed to cloud like http://fly.io. Already benchmarked the http performance of a) nbb-fastify b) node-fastify for a simple text responding endpoint. Would like to create a close-to-real-world service (body parsing, cookie setting, JWT verification etc.) to see how both will play.

👍 1
sher15:10:57

Need your help. How can I import, require a map (config) from a sibling file to parent module? Both reside in the same directory.

;; src/a/core.cljs - parent
(ns a.core
  (:require [--- THE PROBLEM ---]))
;; src/a/config.cljs - required/ child
(def config { answer: 42 })

borkdude15:10:07

you should name your files according to the directory structure, so

src/a/core.cljs
becomes (ns a.core)

borkdude15:10:18

and a/config.cljs becomes (ns a.config)

borkdude15:10:24

and then it's just (:require [a.config])

mjhika15:10:00

borkdude you have lightning fingers

sher15:10:10

If I (:require [a.config]) does it become just config object? or should i qualify the import with :as ?

sher15:10:00

Pardon my noob questions

mjhika15:10:25

i believe you will still need to specify the ns a.config/config

borkdude15:10:35

namespaces aren't objects in clojure

borkdude15:10:54

so you always need to write something behind it:

a.config/config

borkdude15:10:02

I mean, namespaces aren't functions, they also don't have default exports

sher15:10:21

Does the nbb execution params like -cp (classpath) affect this ns/ name resolution?

borkdude15:10:47

also {:paths ["src"]} in nbb.edn

borkdude15:10:01

which is the same as -cp src

sher15:10:52

Thank you. Will endure my struggle.

borkdude15:10:06

Note that this is the same in other Clojure dialects

sher15:10:18

God to know that it is spec compliant.

borkdude15:10:27

feel free to ask more questions

👍 1
sher15:10:46

Being on and off lisp, common lisp, always trying to like clojure/ script. nbb is a good entry (someone already mentioned on X), that does feel familiar.

babashka 1
sher15:10:16

nbb bundle outputs a file with loadString or loadFile methods. Is there a way to tap in to transpiler stages to output the interim JS code for debugging?

borkdude17:10:12

What’s nbb build?

sher19:10:12

Sorry, it was nbb bundle

borkdude20:10:15

@URCRY0U87 no, there's not really a way to tap into this. you can edit the code of course, not sure what you are trying to debug?

sher11:10:18

When getting familiar with js interop, wanted to see what code was actually generated.

borkdude11:10:11

you can also use macroexpand for that

borkdude11:10:31

user=> (require '[applied-science.js-interop :as j])
nil
user=> (j/defn foo [^:js {:keys [a]}] a)
#'user/foo
user=> (macroexpand '(j/defn foo [^:js {:keys [a]}] a))
(def foo (cljs.core/fn ([p__28] (applied-science.js-interop/let [{:keys [a]} p__28] a))))
user=> (require '[clojure.walk :refer [macroexpand-all]])
nil
user=> (macroexpand-all '(j/defn foo [^:js {:keys [a]}] a))
(def foo (fn* ([p__35] (let* [map__36 p__35 map__36 (if false (cljs.core/apply cljs.core/hash-map map__36) map__36) a (applied-science.js-interop/get map__36 :a)] (do a)))))