Fork me on GitHub
#beginners
<
2015-12-16
>
edwthomas02:12:11

Hi, I've just started learning Clojurescript but I'm stuck on something pretty basic. I have some content in my web page that I have set to hidden using CSS. I want to make it visible based on a user click. I could use a library like Domina for that (I think) but if I wanted to do that using just Cljs how should I go about it? I'm a bit confused with the Cljs/JS interop. I can get the element using (.getElementById js/document "my-element"). And then what? How can I access the style and the display property declared in my CSS?

edwthomas02:12:42

Btw I got what I wanted from Domina with a single call to set-styles!. I was thinking I will learn more about how Clojurescript actually works by doing it by hand but maybe its a silly idea simple_smile

trancehime05:12:31

Doing (sort-by val > (frequencies [5 5 1])) gives me ([5 2] [1 1]) but what is a way to get [5 2]?

trancehime06:12:33

oh wow that actually did work.

polymeris13:12:52

@edwthomas: there are several ways to access JS properties

polymeris13:12:04

I like the .- notation

polymeris13:12:30

So you could e.g. do (.-style (.getElementById js/document "my-element"))

polymeris13:12:10

And use set! to change the value

rantingbob14:12:28

@trancehime: How in hte world did you get the bot to do that?

manderson14:12:20

@rantingbob: there's a slash command. If you type /clj (+1 2) it will evaluate it.

trancehime14:12:15

@rantingbob: I didn't actually do that, someone else did - you can see who requested the eval in the ;; comment

jeff.engebretsen15:12:27

What's the Clojure way when it comes to functions receiving invalid arguments? Return nil? Throw an exception? The functions are part of the API of my core library.

snowell15:12:18

clojure.core functions throw IllegalArgumentExceptions, if some other exception doesn’t bubble up first (e.g., ClassCastException)

edwthomas18:12:36

@polymeris: Thanks! I’ll try that out.

edwthomas18:12:13

@polymeris: This worked: (set! (.-display (.-style (.getElementById js/document "my-element"))) "block"). Like with all the minor roadblocks I've experienced in Clojure, once I get some guidance and see something work in the repl, it all makes sense. Thanks!

Drew Verlee22:12:35

What's a top level function (defn) , vs just one created with fn?

donaldball22:12:17

The former creates a var that resolves to the fn