Just submitted a fastify example PR, please take a look https://github.com/babashka/nbb/pull/339
Thanks :)
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.
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 })you should name your files according to the directory structure, so
src/a/core.cljs
becomes (ns a.core)and a/config.cljs becomes (ns a.config)
and then it's just (:require [a.config])
borkdude you have lightning fingers
If I (:require [a.config]) does it become just config object? or should i qualify the import with :as ?
Pardon my noob questions
i believe you will still need to specify the ns a.config/config
namespaces aren't objects in clojure
so you always need to write something behind it:
a.config/configI mean, namespaces aren't functions, they also don't have default exports
Does the nbb execution params like -cp (classpath) affect this ns/ name resolution?
yes
also {:paths ["src"]} in nbb.edn
which is the same as -cp src
Thank you. Will endure my struggle.
Note that this is the same in other Clojure dialects
God to know that it is spec compliant.
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.
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?
Whatโs nbb build?
Sorry, it was nbb bundle
@sherzod 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?
When getting familiar with js interop, wanted to see what code was actually generated.
you can also use macroexpand for that
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)))))