Fork me on GitHub
#clojurescript
<
2019-02-03
>
lilactown00:02:16

super excited that we have nav and datafy in CLJS now! 😄

abdullahibra13:02:55

how could i navigate to specific div in the page from clojurescript?

thheller14:02:55

@abdullahibra what is dommy? are you sure you are calling that right?

abdullahibra14:02:51

@thheller [prismatic/dommy "1.1.0"]

thheller14:02:26

that only takes a bool argument. not a js object

abdullahibra14:02:05

[elem ^boolean align-with-top?]

abdullahibra14:02:12

it takes two args

abdullahibra14:02:22

elem and align-with-top? as boolean type

thheller14:02:08

yeah but you are calling it with elem and the clj->js result (which is not a boolean)

abdullahibra14:02:38

maybe this was old version

thheller14:02:40

you don't really need dommy for this

thheller14:02:08

(defn scroll-to-id
  [target-id]
  (-> (js/document.getElementById target-id)
      (.scrollIntoView #js {:behavior "smooth" :inline "nearest"})))

thheller14:02:09

should do fine

abdullahibra14:02:01

can i scroll to top of div?

abdullahibra14:02:39

inline "start"

abdullahibra14:02:16

that's the right params {:behavior "smooth" :block "end" :inline "nearest"}

Yehonathan Sharvit17:02:38

How do we use type hints in Clojurescript and how does it relate with type inference? I am running this code snippet on version 1.10.516:

(defn bar [^number x]
  (inc x))
  (bar "abc")
And I don’t get any warning. While the following snippet creates a warning
(inc "abc")
cljs.core/+, all arguments must be numbers, got [string number] instead

thheller17:02:33

@viebel pretty sure that is reserved to special js forms currently and not supported via type hints

Yehonathan Sharvit17:02:11

@thheller Is there a support for type hints in cljs?

thheller17:02:04

yes, plenty. the numeric stuff just doesn't take those into account (yet)

mfikes17:02:57

@viebel ClojureScript doesn’t generally use type information for type checking.

Yehonathan Sharvit17:02:04

@mfikes Under what conditions a warning about argument type is emitted?

mfikes18:02:58

@viebel The core numeric macro-functions do this. Outside of this I’m struggling to think of any other specific examples.

Yehonathan Sharvit18:02:11

@mfikes I see. Any idea why in my 1st example above no warning is emitted?

mfikes18:02:21

@viebel Because ClojureScript doesn't generally use type information to perform type checking. There was an experiment that, as an aside, involved adding generic type checking (https://gist.github.com/mfikes/1e2341b48b882587500547f6ba19279d), but ClojureScript probably isn't pursuing that direction.

Yehonathan Sharvit18:02:14

Hmmm @mfikes So what is the big story with type inference?

mfikes18:02:29

ClojureScript has always had basic type inference, and the algorithms have been improving, so that more types are inferred. This is especially true over the past several releases, IMHO.

Yehonathan Sharvit18:02:37

I understand that the algorithms are improving. My question is what value does it bring to developers?

Yehonathan Sharvit18:02:43

Is it in terms of type checking or more efficient transpiled code or something else?

mfikes18:02:39

The latter—type information is primarily leveraged to generate efficient JavaScript.

Yehonathan Sharvit18:02:26

Any interesting example to share?

mfikes18:02:40

Look at what gets generated by and if it knows its arguments are Boolean

mfikes18:02:31

A silly example: the code generated for (str x) when x is known to be a string

mfikes18:02:20

By the way, I’ll be giving a talk about this at Clojure/north

👍 10
Yehonathan Sharvit18:02:11

@mfikes excellent. I am looking forward to watch the video of your talk