This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-28
Channels
- # announcements (14)
- # autochrome-github (1)
- # babashka (4)
- # beginners (151)
- # biff (1)
- # calva (24)
- # cider (13)
- # clara (13)
- # clj-commons (1)
- # cljs-dev (24)
- # clojure (50)
- # clojure-europe (20)
- # clojure-france (13)
- # clojure-nl (4)
- # clojure-norway (12)
- # clojure-spec (43)
- # clojure-uk (6)
- # clojurescript (30)
- # cursive (2)
- # datahike (9)
- # editors (6)
- # emacs (2)
- # fulcro (29)
- # google-cloud (20)
- # graphql (2)
- # humbleui (2)
- # jobs (2)
- # juxt (4)
- # kaocha (5)
- # lsp (14)
- # malli (5)
- # membrane (10)
- # off-topic (39)
- # pathom (21)
- # polylith (10)
- # rdf (8)
- # reagent (4)
- # remote-jobs (3)
- # reveal (18)
- # shadow-cljs (27)
- # spacemacs (7)
- # tools-deps (30)
Apparently I can use (js* "dirname") to read the dirname variable in node. Are there other uses for the js* special form? Is this documented anywhere?
How come that in the REPL:
js/sessionStorage
=> #object [Storage [object Storage]]
While also in the REPL:
(let [sessionStorage js/sessionStorage]
sessionStorage)
=> nil
What gives?
(I'm now using this, but I'm still curious about what it is I am not getting.)
(let [sessionStorage (aget js/window "sessionStorage")]
sessionStorage)
=> #object [Storage [object Storage]]
Never use aget
for anything but JS arrays. In the case above, you can replace it with (.-sessionStorage js/window)
or even js/window.sessionStorage
.
Regarding the issue itself - looks like a bug in CLJS compiler.
Also, seems like using any other name than sessionStorage
on the CLJS side also fixes the issue.
Personally, I prefer using cebab-case for CLJS variables, so I'd go with session-storage
. Or just use js/sessionStorage
directly, without binding it to a different name - after all, there's no reason to do it except for maybe some aesthetic one since js/...
does not incur any computations.
Thanks. What's the reason to not use aget? I'm thinking of it as equivalent to o["some-attribute"]
.
I'll switch to kebab-case especially since that fixes the issue. The reason it was camelCase was that I wanted it to show that it is a JS thing in there. But I agree it is probably better to keep it kebab.
> What's the reason to not use aget? Because it is explicitly only for arrays. Also, it makes it impossible to the compiler to analyze what is used in which context. Might lead to incorrect externs inference IIRC.
I'm not trying to avoid computations, actually. 😃 I'm mocking local and session storage to be able to test it and also for the code to just run in nodejs, where the test runner lives.
I was trying to create a local binding
(let [window (js/window.open ,,,)]
,,,)
and was confused why I was getting nil
on the left hand side. renaming the binding to win
fixed itHaha, I guess you realized it was a bug. I was more like ”TIL!" and went to the rvalue to see if I could make it return what I wanted. 😃
that is somewhat tricky to handle since we cannot possibly know about all things at the top-level
this would be more concerning if this was true within functions - which I believe we fixed many cases long ago
need something inside a defn
that demonstrates the issue - again we have lots of shadowing code so need to find where gap is
Here's a session using ClojureScript Getting Started instructions:
$ clj -M --main cljs.main --compile hello-world.core --repl
ClojureScript 1.11.4
cljs.user=> (defn f1 []
(let [window js/window]
window))
(defn f2 []
(let [vindow js/window]
vindow))
#'cljs.user/f1
cljs.user=> cljs.user=> #'cljs.user/f2
cljs.user=> (f1)
nil
cljs.user=> (f2)
#object[Window [object Window]]
cljs.user=>
I've updated https://ask.clojure.org/index.php/11607/binding-js-variable-to-variable-binds-nil. I think the JIRA ticket also needs a new description.Hey all - is there a built in function I can use to replace the js* form in (js* "~{} ** ~{}" (js/BigInt 10) (js/BigInt 2))
Math/pow
won’t work on bigints
Doesn't seem like it - the whole CLJS codebase does not include **
anywhere except in comments.
that’s what I had found too
Here's a session using ClojureScript Getting Started instructions:
$ clj -M --main cljs.main --compile hello-world.core --repl
ClojureScript 1.11.4
cljs.user=> (defn f1 []
(let [window js/window]
window))
(defn f2 []
(let [vindow js/window]
vindow))
#'cljs.user/f1
cljs.user=> cljs.user=> #'cljs.user/f2
cljs.user=> (f1)
nil
cljs.user=> (f2)
#object[Window [object Window]]
cljs.user=>
I've updated https://ask.clojure.org/index.php/11607/binding-js-variable-to-variable-binds-nil. I think the JIRA ticket also needs a new description.