nbb

jf 2025-05-28T10:09:07.211939Z

I’m just trying out applied-science.js-interop/get-in, and I’m not exactly sure how to use it for nested lookups (which, surely, that’s what it’s for?). Even after accounting for the fact (?) that the literal #js seems to only keywordize at the first level, I still have an issue:

user=> (require '[applied-science.js-interop :as j])
nil
user=> #js{"a" {"b" {"c" 9}}}
#js {:a {"b" {"c" 9}}}
user=> (def abc #js{"a" {"b" {"c" 9}}})
#'user/abc
user=> abc
#js {:a {"b" {"c" 9}}}
user=> (j/get-in abc [:a])
{"b" {"c" 9}}
user=> (j/get-in abc [:a "b"])
nil
user=> (j/get-in abc [:a :b])
nil
user=>
Is this an issue with get-in... or am I somehow not using it correctly?

jf 2025-06-01T01:57:03.286489Z

speaking of clj->js and j/lit: what is the difference between them and when would one use one vs the other?

borkdude 2025-06-01T06:59:07.048539Z

They do the same thing but j/lit tries to do more at compile time

borkdude 2025-05-28T10:17:34.881549Z

j/get-in only works on JS data structures. #js only creates a one-level JS object. So if you don't write #js before the inner objects, they become normal CLJS data structures for which j/get-in is not intended to be used.

borkdude 2025-05-28T10:17:57.953749Z

If you need a nested JS structure, either use multiple #js , use clj->js or use j/lit

borkdude 2025-05-28T10:18:18.865509Z

user=> (def abc (j/lit {"a" {"b" {"c" 9}}}))
#'user/abc
user=> (j/get-in abc [:a :b])
#js {:c 9}

jf 2025-05-28T10:37:08.215509Z

🙏 Gotcha. Thank you yet again for another saving reply!

🙏 1