Fork me on GitHub
#clojurescript
<
2019-09-06
>
ag00:09:59

Does anyone know if it is possible to slurp an externs.js file for a cljsjs package?

ag00:09:18

I need to access externs.js file (for a cljsjs package) from Clojure. What’s the best way of doing that

Drew Verlee00:09:27

Have any of the ideas from atomic-layout been ported to clojure? Or does anyone have any thought or opinions on it? I'm just starting to look into it and i'm not sure i get the picture just yet.

mfikes02:09:52

@ag If you know the name of the file in the JAR, you could use io/resource to access it, like this:

$ clj -Sdeps '{:deps {cljsjs/react {:mvn/version "16.9.0-0"}}}'
Clojure 1.10.1
user=> (require '[ :as io])
nil
user=> (slurp (io/resource "cljsjs/react/common/react.ext.js"))

mfikes02:09:09

You could even get at the name of the externs file like this

user=> (:externs (read-string (slurp (io/resource "deps.cljs"))))
["cljsjs/react/common/react.ext.js"]

mfikes02:09:44

Oh, sorry, just noticed the crosspost on #clojure

ag16:09:54

That is exactly what I needed. Once again, you saved my day. And I have failed to properly explain what my problem is in #clojure, so I didn’t get right answers immediately.

martinklepsch16:09:13

Are the performance characteristics for :extend-via-metadata protocols different than for regular protocols?

Alex Miller (Clojure team)16:09:31

if true, then you have 3 options - direct invocation, always tried first, no difference in perf

Alex Miller (Clojure team)16:09:07

metadata extension second, external extension third

Alex Miller (Clojure team)16:09:18

b/c #2 is checked, #3 is slower

Alex Miller (Clojure team)16:09:56

or rather, all the answers above are for Clojure. I assume similar for cljs, but could be wrong.

martinklepsch16:09:32

Thanks! Im not sure I fully understand what you’re referring to with “external extension” though? extend-type?

scknkkrer17:09:01

How about WASM ? Are we ready to it ? Are there any implementation ?

Vesa Norilo17:09:24

not sure how much upside there would be at this point

Vesa Norilo17:09:57

a large runtime, including gc, would be required

Vesa Norilo17:09:52

also, clojure being hosted, there’s not really anything on the host side in wasm

kenny19:09:48

Ok, something super weird is going on with some data I have. I'm in a CLJS REPL:

x
=>
[{[:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"] [{(:metric/dashboard-series
                                                              {:window [#inst"2019-09-06T16:20:32.277-00:00"
                                                                        #inst"2019-09-06T19:20:32.277-00:00"]}) [:dashboard-series/name
                                                                                                                 :dashboard-series/points]}]}]
y
=>
[{[:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"] [{(:metric/dashboard-series
                                                              {:window [#inst"2019-09-06T16:20:32.277Z"
                                                                        #inst"2019-09-06T19:20:32.277Z"]}) [:dashboard-series/name
                                                                                                            :dashboard-series/points]}]}]
(= x y)
=> false
Those two data structures are identical... but apparently they aren't? I'm almost 100% certain it has to do with the list.

kenny19:09:48

(= (get (first x) [:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"])
   (get (first y) [:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"]))
=> false

thheller19:09:06

@kenny it is the dates ie. #inst

kenny19:09:41

I don't think so. This arose because I couldn't write some transit:

(cognitect.transit/write
  (cognitect.transit/writer :json)
  y)
Error: Cannot write 

kenny19:09:10

That error goes away when I get rid of the list.

thheller19:09:05

hmm you are right. dates seem to be fine

kenny19:09:19

x was defined like this:

(def x '[{[:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"] [{(:metric/dashboard-series
                                                                       {:window [#inst"2019-09-06T16:20:32.277Z"
                                                                                 #inst"2019-09-06T19:20:32.277Z"]}) [:dashboard-series/name
                                                                                                                     :dashboard-series/points]}]}])
y was defined by pulling some data off something generated at runtime.

kenny19:09:05

If I dig way into that structure, it is actually a List

(type (first (keys (first (get (first y) [:metric/id #uuid"0a9640da-13a0-49b6-9e82-87b38ac2619f"])))))
=> cljs.core/List

kenny19:09:15

y also came from a macro, in a way.

kenny19:09:11

But the macro isn't doing anything strange. It's just pulling the value out and putting it in another place. Either way, the two values look fine.

kenny19:09:09

Well that was fun... Turns out it was the dates! The dates were generated from cljs-time haha

kenny19:09:43

Not sure that I agree with cljs-time on writing a cljs-time object just like a #inst

andy.fingerhut20:09:00

Out of curiosity, was the issue that two different types of object were being printed as #inst <something>, so they looked textually the same when printed, but were not = to each other in Clojure because of the different types?