This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-23
Channels
- # announcements (2)
- # babashka (25)
- # beginners (33)
- # biff (13)
- # calva (13)
- # clerk (82)
- # clj-commons (3)
- # clj-kondo (8)
- # clj-on-windows (23)
- # cljdoc (6)
- # clojure (16)
- # clojure-belgium (1)
- # clojure-dev (58)
- # clojure-europe (53)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-uk (2)
- # clojurescript (17)
- # core-async (5)
- # cursive (6)
- # datahike (1)
- # datomic (8)
- # emacs (25)
- # etaoin (21)
- # events (4)
- # graalvm (33)
- # honeysql (7)
- # hyperfiddle (1)
- # lsp (49)
- # luminus (4)
- # malli (18)
- # off-topic (63)
- # reagent (11)
- # releases (1)
- # shadow-cljs (200)
- # timbre (1)
- # tools-build (17)
Is there a way to do https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining with cljs/`aget`? const dogName = adventurer.dog?.name;
Sorry I should have clarified that I mean on nested JS objects.
Oh wait, I see.
(some-> (clj->js {:a {:b {:c 1}}}) (aget "a" "d"))
Wait am I doing something dumb here. :thinking_face:
Yep so this throws:
(some-> (clj->js {:a {:b {:c 1}}}) (aget "a" "d" "n"))
Ok got it:
(some-> (clj->js {:a {:b {:c 1}}}) (aget "a") (aget "d") (aget "c"))
👍 2
This might also be useful:
cljs.user=> (goog.object/getValueByKeys (clj->js {:a {:b {:c 2}}}) "a" "b" "c")
2
cljs.user=> (goog.object/getValueByKeys (clj->js {:a {:x {:c 2}}}) "a" "b" "c")
nil
🙏 2
@UUSQUGUF3 I saw this library used at my job. I like it: https://github.com/applied-science/js-interop
> To cohere with Clojure semantics, j/get
and j/get-in
return nil
if reading from a nil
object instead of throwing an error.
js: adventurer.dog?.name
cljs: (j/get-in adventurer [:dog :name])
❤️ 2