This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-31
Channels
- # announcements (5)
- # babashka (5)
- # beginners (24)
- # calva (21)
- # cherry (1)
- # clerk (20)
- # clj-kondo (3)
- # clj-otel (12)
- # clojure (50)
- # clojure-austin (2)
- # clojure-conj (3)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (203)
- # clojure-spec (3)
- # clojure-uk (6)
- # clojurescript (8)
- # conjure (1)
- # datomic (1)
- # deps-new (1)
- # emacs (5)
- # graphql (8)
- # gratitude (5)
- # holy-lambda (16)
- # honeysql (18)
- # hyperfiddle (12)
- # java (1)
- # jobs (1)
- # lsp (24)
- # membrane (8)
- # nbb (1)
- # off-topic (19)
- # portal (28)
- # proletarian (11)
- # rdf (63)
- # re-frame (38)
- # reagent (8)
- # reitit (1)
- # releases (6)
- # remote-jobs (1)
- # scittle (4)
- # shadow-cljs (20)
- # spacemacs (4)
- # sql (7)
- # transit (1)
Is there not a non-macro way of getting a JS property?
(.. theme -colorSchemes -light -palette -bm -test -x))
This is fine, except that -light
is hardcoded for now. It's actually a variable mode
.
So what I really want is this:
(.. theme -colorSchemes mode -palette -bm -test -x))
Except that this won't work, since it's a macro form and it won't expand.
It feels rather silly having to wrap such a simple thing in a helper macro just so I can have my var eval'd.
Is there a better way? Esp. since macros in CLJS are a bit of a pain.Have you tried using goog.object/getValueByKeys
?
(def example #js {:nested #js {:one 1 :two 2}})
(defn get-nested [num]
(goog.object/getValueByKeys example #js ["nested" num]))
(get-nested "one") ;=> 1
(get-nested "two") ;=> 2
👍 2
And me writing this ugly macro in the meantime
(defmacro get-colour [theme mode & parts]
`(do ;(prn :get-colour :mode ~mode)
(if (= ~mode :light)
(.. ~theme -colorSchemes -light -palette ~@parts)
(.. ~theme -colorSchemes -dark -palette ~@parts))))
🙈This thread has some useful functions from closure library that are hard to find, but they’re with you at all times if you use CLJS. https://clojureverse.org/t/cljs-hidden-google-closure-library-gems/2321

❤️ 2
if there is only one dynamic part you can still leave the rest hard coded, just using ->
instead of ..
is more flexible
@hifumi123 that's it! Thanks.