Fork me on GitHub
#clojurescript
<
2017-01-09
>
dnolen00:01:20

@notanon not yet in a release

zentrope04:01:04

How do you test of an item is an instance of date in cljs?

cfleming04:01:34

I’m trying to use http://clojure.browser.net to make an XHR request. What I have works fine in dev, but when I use advanced compilation and deploy to prod, it doesn’t work. In the network panel, I can see the request completing correctly with the correct response, but it seems like none of the events are getting triggered.

cfleming04:01:59

I’ve enabled all the XHR breakpoints in Chrome, and the only one that is hit is readystatechange

cfleming05:01:50

This works fine with :simple optimizations, but it doesn’t use any non-CLJS or non-Goog code.

cfleming05:01:23

I’ll try to make a repro case if I get a moment.

cfleming07:01:16

I fixed this by using the goog enum instead of the corresponding keyword - TIL.

danielcompton08:01:11

I didn't even realise that keywords could be used in place of the enums. That seems like a dangerous feature as it will break under advanced compilation?

jarradhope09:01:54

shameless plug: We're building a open source mobile browser, messenger, and gateway to a Ethereum blockchain based on decentralised technologies and seeking contributors https://status.im/ http://wiki.status.im/

jarradhope09:01:22

re-natal + re-frame + cljs + golang

pesterhazy11:01:19

Does anyone have experience with React table components? I'm looking at https://github.com/bvaughn/react-virtualized and https://github.com/reactabular/reactabular in particular. Ideally it should take a vector of maps and handle displaying autonomously for the most part.

pesterhazy13:01:08

@sbmitchell, hey I saw that you used react-virtualized with clojurscript

pesterhazy13:01:33

I'm trying to get it to work but seeing stacktraces related to ReactDOM

pesterhazy13:01:28

Did you do anything special to get it to work with the cljsjs package?

pesterhazy15:01:05

I've found sort-by to be very slow when sort-fn is expensive

pesterhazy15:01:59

For example, if I sort by fmt-value, it takes an order of magnitude longer than

pesterhazy15:01:04

(->> items
         (map (juxt (comp fmt-value f) identity))
         (sort-by first)
         (mapv second))

pesterhazy15:01:23

Has anyone noticed that?

pesterhazy15:01:49

(in the example, fmt-value would be slightly costly, e.g. keyword or str)

rauh16:01:46

@pesterhazy That's expected, since your fmt-value function will be called O(n log n) times during the sort and only exactly N times in the other case

rauh16:01:06

So you basically precompute part of the comparator values.

rauh16:01:25

If performance is critical you can go for a non-stable sort (garray/sort ...)

pesterhazy16:01:20

I assume garray/sort also calls the compare-fn O(n log n) times?

rauh16:01:33

Yes on average

pesterhazy16:01:01

hmm, so is my fast-sort-fn actually the best I can do?

pesterhazy16:01:43

that's reasonably fast even if compare-fn is slow

pesterhazy16:01:07

a generalized sort-fn that only calls compare-fn n times

pesterhazy16:01:16

is what I'm looking for I guess

rauh16:01:10

The first fn still gets called nlogn times, but the values will be precomputed, which is a good idea in case you do some formatting (which can slow)

pesterhazy16:01:42

yeah, first is fast I guess

rauh16:01:27

Lots of ways to potentially get some more performance out of it if you just use (.sort (to-array ...) (fn [a b] ...)) and do the compare manually

pesterhazy16:01:06

right but that would still call compare-fn >n times, correct?

rauh16:01:40

Yes, no way around that, but the stable sort will wrap it again and copy the array again.

pesterhazy16:01:07

thanks for your help!

pesterhazy16:01:24

some useful pointers

rauh16:01:31

@pesterhazy If you end up writing an optimized fn, let me know and gist it. I could use it probably

rauh16:01:25

So sketch: Create array manually, add the "cached" value to be compared as arr[0] and payload to arr[1], then return the arr[1] elements in the end (and seq it)

pesterhazy16:01:13

basically like my version above except using js arrays in place of vectors

rauh16:01:12

Yeah pretty much

bostonaholic19:01:12

@dnolen could you please point me to some docs explaining the usage of aget and also when you shouldn’t use aget?

bostonaholic19:01:17

google is failing me

dnolen19:01:20

Easy - arrays

bostonaholic19:01:35

yeah, but my colleagues don’t believe me

bostonaholic19:01:47

and I’ve told them “but David Nolen says…"

bostonaholic19:01:53

apparently that isn’t enough 😜

martinklepsch19:01:07

@bostonaholic there’s a stackoverflow thread somewhere, maybe look there specifcally 😄

dnolen19:01:32

@bostonaholic: aget usage is arrays only just like Clojure. No other information is necessary

bostonaholic19:01:20

so how would one retrieve nested map data on js/window?

dnolen19:01:47

In the future if the compiler starts warning about incorrect don't be surprised

dnolen19:01:19

goog.object is the namespace for dealing with dynamic objects

joshjones19:01:43

as I’m new to cljs, just to be clear, you’re saying to use (.-propname el) instead of (aget el “propname”) unless el is a javascript array?

dnolen19:01:27

aget is only for arrays

dnolen19:01:44

If you're not operating on arrays your code is wrong

bostonaholic19:01:14

@joshjones yes or use (goog.object/get el “propname")

bostonaholic19:01:13

now I really want to open a PR in my app to replace all incorrect usages of aget

joshjones19:01:35

thanks to you both

jr19:01:31

I usually just make a util function for js objects

(defn get-in [obj keys]
(reduce goog.object/get obj keys))

bostonaholic19:01:02

(I haven’t watched the video yet so I’m unsure of the correctness)

jr19:01:17

not sure if reducing on goog.object/get can be optimized by closure though

bostonaholic19:01:17

but the section at the bottom on aset/aget is helpful

dnolen19:01:21

Right goog.object is got dynamic property access. Use property syntax for anything the compiler is guaranteed to either see the definition of, or an extern has been provided for

dnolen19:01:48

got -> for

notanon19:01:28

what does dynamic property access mean in js? isn't all object property look up the same? (forgive my ignorance)

notanon20:01:07

i understand on the jvm avoiding reflection is very important, but i don't know of a js parallel

dnolen20:01:18

the property is not statically knowable by Google Closure

dnolen20:01:59

I don’t mean dynamic property access for javascript, I mean dynamic property access for ClojureScript

darwin21:01:16

@bostonaholic check out oget as a smart alternative to aget : https://github.com/binaryage/cljs-oops

qqq23:01:50

Uncaught Error: No print-fn fn set for evaluation environment <-- how do I fix this? caused gy using pprint from cljs

angusiguess23:01:01

@qqq if you're in a browser, (enable-console-print!) should fix it

gfredericks23:01:24

does anybody understand the rationale for the "env" half of the dispatch value of cljs.test/report?

qqq23:01:32

@angusiguess : fixed it; thanks!

gfredericks23:01:00

e.g., a use case where changing the env is a better way of doing something than anything you can do in jvmland-style?

cfleming23:01:33

@gfredericks In general the reporting mechanism is fragile. I use it in Cursive to provide the test integration, but things like humane-test-output break it.

cfleming23:01:24

I don’t have a good solution unfortunately - I’m considering hooking the default reporting mechanisms, reporting in some out-of-band way (over a socket to the IDE, or something), and then calling the original methods to ensure everything stays working.

cfleming23:01:37

It starts becoming a frankensolution at that point though.

cfleming23:01:58

Anyway, I can’t actually answer your question, sorry, but I do sympathise 🙂

gfredericks23:01:29

I think for my problem (something called karma uses a nalternate env keyword) it would work if karma had its env extend the default, in the namespaced-keyword-inheritance-hierarchy-thing