This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-18
Channels
- # aleph (1)
- # announcements (31)
- # babashka (9)
- # babashka-sci-dev (36)
- # beginners (72)
- # calva (20)
- # clj-kondo (99)
- # cljsrn (1)
- # clojure (77)
- # clojure-europe (33)
- # clojure-nl (4)
- # clojure-norway (12)
- # clojure-uk (4)
- # clojurescript (23)
- # cursive (2)
- # datascript (5)
- # events (1)
- # fulcro (3)
- # honeysql (3)
- # inf-clojure (82)
- # interop (2)
- # kaocha (10)
- # lsp (15)
- # meander (1)
- # missionary (10)
- # off-topic (22)
- # pathom (4)
- # pedestal (3)
- # polylith (20)
- # re-frame (10)
- # react (4)
- # reagent (4)
- # reitit (27)
- # ring-swagger (1)
- # shadow-cljs (34)
- # specter (3)
- # sql (1)
- # testing (5)
- # tools-deps (22)
- # vim (12)
Following up on yesterday's discussion: wrapping my unwanted code in delay
helped the compiler eliminate it.
Taking a closer look at the JS output, I notices that there are other function calls that the DCE doesn't seem to eliminate, such as the following.
Sets:
(def unused-set #{...})
becomes
PersistentHashSet$createAsIfByAssoc(...);
Atoms:
(def unused-atom (atom ...))
becomes
cljs$core$atom(...);
Some fn calls:
(defn f [x] (str x "bar")
(def unused-map {:a {:b (f "foo")}})
becomes
$f$ = function($x$) {[$str$($x$), "bar"].join("");};
$f$("foo");
It seems like if possible, helping the Closure compiler eliminate these things could lead to pretty large savings in some circumstances. The emitted JS for some parts of my codebase consists almost entirely of this type of dead code.@wombawomba that is interesting about delay
- but I don't really see anything pressing for us to do here
@wombawomba — I would be super interested in a short summary of tips how to write code that optimizes for code elimination based on your findings 🙂
by pressing I mean nothing critical wrt. priority - some of these seem like minor patches we'd be happy to take if provided
@ferdinand sure, I'll write something up
Thanks 🙂
Some people like timbre: https://github.com/ptaoussanis/timbre
Was using timbre, but now thinking limiting the unnecessary dependencies. Since Goog ships with cljs, I shall directly use goog
Google Closure Library has a logging thing - I believe it's been wrapped to be generic by some open source libs?
have used it directly, and wrapped in some cases, haven't personally found shared logging to be particularly useful
Hello, I’m trying to translate some JS to CLJS and running into an error. Does this syntax look correct? Working JavaScript
const processor = unified()
.use(parse)
.use(uniorg2rehype)
.use(rehypeParse)
.use(rehypeReact, { createElement }) // Same error if I comment this line
const file = await processor.process(`* org-mode example\n your text goes here`);
console.log(file.result);
Not working ClojureScript (Uncaught TypeError: Cannot process
without Compiler
)
(def processor (-> (unified)
(.use org-parse)
(.use org-to-rehype)
(.use rehype-parse)
(.use rehype-to-react (clj->js {:createElement createElement})))) ;; I think the problem is here
(go (let [file (<p! (.process processor "* org-mode example\n your text goes here"))] ;; Fails here
(.log js/console (:result file))))
Depending on what createElement
is exactly, maybe replacing (clj->js {...})
with #js {...}
will help.
Apart from that, your code looks pretty much what it should be.
If that <p!
is the only reason you need the go
block here then I wouldn't use it at all - IMO better to use promise API, i.e. (.then ... (fn [file] ...))
.
Thanks @U2FRKM4TW, I did also try #js {...}
, same issue.
and FWIW don't use go
for a single "await". use .then
instead. the go
will generate substantially more code when this is all you really need.
(-> (.process processor "* org-mode example\n your text goes here")
(.then (fn [^js file]
(js/console.log (.-result file)))))
Thanks @U05224H0W! That was my initial syntax error. Also, note taken about go
There is another issue underlying this one since rehype-react is an ESM only package. I’ll ask in #shadow-cljs.