This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-21
Channels
- # 100-days-of-code (5)
- # announcements (6)
- # beginners (92)
- # cider (39)
- # cljdoc (35)
- # cljsrn (1)
- # clojure (187)
- # clojure-sanfrancisco (2)
- # clojure-spec (26)
- # clojure-sweden (2)
- # clojure-uk (1)
- # clojurescript (27)
- # cursive (19)
- # datascript (3)
- # datomic (19)
- # defnpodcast (1)
- # emacs (11)
- # fulcro (71)
- # incanter (1)
- # lein-figwheel (4)
- # lumo (10)
- # off-topic (19)
- # planck (5)
- # reagent (49)
- # reitit (2)
- # shadow-cljs (25)
- # spacemacs (1)
- # sql (1)
- # unrepl (4)
- # yada (4)
why does clj -m cljs.main -re node -e '(println "hello")' -e '(.exit js/process 0)'
hang?
Maybe something in this loop fails to realize Node is no longer alive, blocking on some I/O indefinitely https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/repl/node.clj#L91-L110
I’m currently leaning to (exists? js/process)
but that’s a bit brittle, and not very explicit
these tests can be tricky, there's so much of polyfills that can distort the result, in one project at my company I just used this https://www.npmjs.com/package/is-node
Cool, thanks for the pointers. Does seem a bit involving. Maybe I should just explicitly do (exists? js/process.env)
, since that’s what it’s all about anyway.
Oh, that’s actually a goog-define
so if you are using :advanced
you can eliminate conditional code that way…
I’m using :none
, but just to understand, what conditional code would I be able to eliminate?
@grav If you look at the source for array?
, copied here for reference,
(defn ^boolean array?
"Returns true if x is a JavaScript array."
[x]
(if (identical? *target* "nodejs")
(.isArray js/Array x)
(instance? js/Array x)))
when this is passed through :advanced
since identical?
is being used, Google Closure Compiler can strip the code down to just
(.isArray js/Array x)
(This is normal conditional code elimination that you can do using :closure-defines
)See the sentence "You can use the variables set in :closure-defines
to eliminate parts of your code at compile time (DCE). " at https://clojurescript.org/reference/compiler-options#closure-defines
Sorry for jumping in, is identical?
mandatory for dce? Can an =
be used instead?
And, just saying a nice thing about this is that it can work in library code, and is compatible with :aot-cache
, all because this "stripping" is deferred until :advanced
processing.
Impressive what the Closure compiler can do. I’m probably not appreciating it as much as it deserves 🙂
Perhaps related and of interest to you https://github.com/anmonteiro/lumo/issues/424