This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-13
Channels
- # announcements (1)
- # asami (6)
- # babashka (7)
- # beginners (94)
- # biff (1)
- # calva (18)
- # clj-kondo (35)
- # cljsrn (1)
- # clojure (7)
- # clojure-europe (1)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (18)
- # core-logic (1)
- # datalog (2)
- # editors (10)
- # exercism (2)
- # figwheel-main (1)
- # fulcro (2)
- # introduce-yourself (1)
- # lsp (33)
- # malli (7)
- # off-topic (3)
- # pedestal (1)
- # portal (2)
- # re-frame (16)
- # releases (1)
- # shadow-cljs (10)
- # specter (3)
- # tools-deps (8)
Hey, I'd like to target the :last-child
selector via makeStyles
to override the padding of a mui component. Any idea how do to it?
Here's what I did which doesn't work:
(def usCustomStyles
(makeStyles
#js{:card-content
#js{:padding "24px 40px 40px 40px"
"&:last-child" {:padding-bottom "40px"}}}))
Wild guess since I don't know the problem domain, but could it be a missing #js in the most nested map?
Let me try that.
Trying to use map-indexed
to generate some markup. The code looks like it should work but I don't see why it doesn't:
(def image-list ["image1.png" "image2.png" "image3.png"])
(def image-grid []
[image-list {:cols 4 :row-height 120 :gap 0}
(map-indexed (fn [index item]
[image-list-item {:key index :cols 1}
[:img {:src (:img item)}]])
image-list))
I see why.
What do you reach for if you want a custom keyword function when performing js->clj
?
Using nbb which fortunately had cljs-bean built in already and the bean
function accepted a keyword function
Did try copying the js->clj function but not sure those base protocols like IClojureEncode and the Map related one it uses are exposed through nbb. Plus cljs-bean is noticeably faster
If cljs-bean
works for you then good.
> not sure those base protocols like IClojureEncode and the Map related one it uses are exposed through nbb
But do you need those protocols? And if you do, does cljs-bean
support them?
I'm not really sure if they're needed or not, it's possible they were not needed. cljs-bean works in a different way https://github.com/mfikes/cljs-bean
Right, I know. I'm just pointing out that you probably don't need those protocols that js->clj
handles.
If you work with plain old JS object aka JSON data then this is all you need:
(defn my-js->clj [v key-fn]
(cond
(object? v) (into {}
(map (fn [[k v]]
[(key-fn k) (my-js->clj v key-fn)]))
(js/Object.entries v))
(array? v) (mapv #(my-js->clj % key-fn) v)
:else v))
As a less obvious alternative, it's very often the case that any sort of JS->CLJS conversion is completely unnecessary.
There is still interop, and JS arrays are seqable - you can see in the code above that mapv
and into
do work on them with no issues, and even that [k v]
destructuring works.
That makes sense
Might end up going with something like the above solution, ran into a strange behavior that I don't think is intentional. https://github.com/mfikes/cljs-bean/issues/89
I left a comment there. But even if you fix the behavior by introducing ad-hoc code for UID
, I still wouldn't use cljs-bean
here and instead would prefer regular interop unless there's a good reason not to. That get-in
then becomes (.. ^js data -properties -UID -formula -string)
. Although you mention spaces in field names, and those do bring the need for goog.object
.
True it only took a few seconds to get the regular interop working with that solution vs the bean approach seems like I'd be spending more time trying to create the counterpart to turn the key back into a prop and likely hit more bumps along the way