This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-16
Channels
- # announcements (7)
- # babashka (1)
- # beginners (25)
- # calva (7)
- # cider (15)
- # clj-kondo (13)
- # cljdoc (14)
- # clojure (151)
- # clojure-europe (4)
- # clojure-hamburg (2)
- # clojure-italy (22)
- # clojure-nl (57)
- # clojure-spec (12)
- # clojure-uk (6)
- # clojuredesign-podcast (5)
- # clojurescript (12)
- # core-async (8)
- # cursive (26)
- # datascript (9)
- # datomic (92)
- # emacs (4)
- # fulcro (7)
- # graalvm (1)
- # graphql (2)
- # instaparse (3)
- # jobs (1)
- # jvm (2)
- # kaocha (6)
- # nrepl (3)
- # off-topic (5)
- # re-frame (45)
- # reagent (5)
- # reitit (18)
- # ring (1)
- # shadow-cljs (89)
- # slack-help (9)
- # spacemacs (2)
- # sql (54)
- # tools-deps (75)
- # vim (28)
- # xtdb (17)
- # yada (31)
I have a strange bug in my re-frame app. Simply put, these lines
(.log js/console user)
(println (get user "displayName" "anonynous"))
print the following:
subs.cljs:16 {... displayName: "John Doe"}
core.cljs:192 anonynous
The user does contain a key named displayName
, but when I log it it can't find it.
I can put here all of the events and effects of re-frame, but the problem is right thereIt seems that user
is a regular JS object. Try using (.-displayName user)
or goog.object/get
.
what is the best practice when combining js and clj? I get stuck at it all the time.. should I transform js object to clj? or use the goog lib?
It depends no the nature of that object. If it's data, I thik you should use either goog.object/get
or cljs-oops
. If it's some instance of some type, you should probably use externs inference and regular JS interop, especially if you use shadow-cljs
. I keep using cljs-oops
for the latter as well though.
In general, you can't use (.-displayName user)
for neither data nor code because it probably won't work in production where GCC is run with :advanced
optimizations.
cant i transform js object (data) to cljs data? I thought that was the point of js->clj
You sure can! And I think there are libraries out there that claim to do it faster than js->clj
if you care about it.
But you should do it only if you need the complete data. If you just need a single field, there's no point in converting the whole data.
Also, js->clj
will not work for non-data objects (i.e. where (not (identical? (type x) js/Object))
.