Fork me on GitHub
#clojurescript
<
2020-07-01
>
Casey11:07:45

In cljs, do records have a perf advantage when accessing named members like in clj?

dvingo13:07:35

yep. you can easily measure such things:

(defrecord MyRec [a])
(let [a {:a 5}
      b (->MyRec 5)]
  (time
    (dotimes [i 1e7]
      (:a a)))
  (println "record:")
  (time
    (dotimes [i 1e7]
      (:a b)))
  )
"Elapsed time: 267.300000 msecs" record: "Elapsed time: 10.745000 msecs"

❀️ 3
dvingo13:07:56

you can view the compiled js to understand why: http://app.klipse.tech/

Casey14:07:43

Many thanks!

dvingo15:07:05

sure thing!

dazld12:07:37

when testing a value such as a map for IEquiv - it looks like the hash values are ignored. is that correct, and if so, why?

dazld12:07:34

(i'd assumed that the hash property of values was a quick way to check equivalence, but looks like they don't take part, really curious what's going on)

thheller12:07:20

hash isn't guaranteed to be unique so it would be bad for equiv checks

πŸ‘ 3
Alex Miller (Clojure team)12:07:11

hash can be a good fail fast option so it makes sense in that sense

Alex Miller (Clojure team)12:07:33

(and identity can be a good pass fast option)

Alex Miller (Clojure team)12:07:48

but to truly test deep equality, you can have to check values

πŸ‘ 3
dazld08:07:43

thanks for the info both, really interesting. is it the same in CLJ or is this a CLJS quirk?

lilactown16:07:09

I'm thinking of doing some live coding of some OSS ClojureScript I'm working on. if people want to tune in and hang out I thought that might be fun πŸ™‚ anyone interested?

πŸ‘ 24
adam17:07:31

Why this is always printing even when the class is not available:

(when-let [elms (gdom/getElementsByClass "navbar-burger")]
  (.log js/console elms))))

dpsutton17:07:55

what is it printing?

adam17:07:21

NodeList []

dpsutton17:07:30

that's not falsy

dpsutton17:07:32

that's something

dpsutton17:07:36

(when-let [x []]
  (prn x))
[]

dpsutton17:07:55

x is bound to [], in your case, x is bound to a nodelist

flyboarder17:07:56

@somedude314 that should always return a list

flyboarder17:07:16

even if it’s empty, it should be a NodesList array

flyboarder17:07:15

an object, even empty, is a true value

adam17:07:43

I see, thanks

dpsutton17:07:25

although (gdom/getElementByClass "container") returns nil for me

adam18:07:34

Nice will use that - I have one navbar per page

dpsutton18:07:51

i think that usage is incorrect is my point

dpsutton18:07:01

it takes a root element as far as i can tell

dpsutton18:07:08

i'm sorry. i was looking at https://google.github.io/closure-library/api/goog.dom.html and i must have gotten the wrong one. i thought its signature was element classname

dpsutton18:07:45

also, check out array-seq if you do expect more than one

πŸ†— 3
cap10morgan19:07:47

Anyone using tools-deps + cljs-test-runner w/ node + jsdom for CLJS tests? Having a hard time getting it working.

Baishakhi Saha23:07:47

anyone trying clojurescript + figwheel-main + implementing client side routing using reitit?