Fork me on GitHub
#clojurescript
<
2018-12-30
>
mbossenbroek04:12:17

hi, trying to follow a d3 example, not sure why the following translation doesn’t work... https://github.com/d3/d3-scale js:

var x = d3.scaleLinear()
    .domain([10, 130])
    .range([0, 960]);

x(20); // 80
x(50); // 320
cljs:
(require '[cljsjs.d3])
(def x
  (-> js/d3
      (.scaleLinear)
      (.domain [10, 130])
      (.range [0, 960])))

(x 20) ;; nil
(x 50) ;; nil
If I do (js/console.log x), it prints the following function:
ƒ scale(x) {
    return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  }
Is there a different way to call x? I tried many variations of dot forms and js-invoke with no luck

gordon04:12:31

@mbossenbroek try using the #js tag before those vectors, D3 likely expects JS arrays https://cljs.github.io/api/syntax/js-literal

mbossenbroek04:12:08

perfect! I never would have guessed that one. 🙂 Thanks!

👍 4
lilactown07:12:15

(require '[clojure.tools.reader.edn :as edn])
;=> nil
(edn/read-string "#inst \"2010-11-12T13:14:15.666\"")
;=> #error {:message "No reader function for tag inst.", :data {:type :reader-exception, :ex-kind :reader-error}}

lilactown07:12:09

I thought this should create an #inst?

folcon10:12:41

@phill It does, (fiddlyness with records being a mess from my perspective). Lots of unobvious steps that I had to do. I was thinking of turning it into a macro, but I don’t have too much experience writing those, so I was worried I’d end up putting together some ghastly thing that would invariably trip me up in future…

bronsa11:12:42

@lilactown the end reader doesn't have any reader tags registered by default, as it doesn't use the global var but takes a map parameter

bronsa11:12:36

that matches the clojure.edn api so we're not going to diverge there

lilactown14:12:49

@bronsa AFAICT both clojure.tools.reader.edn and clojure.edn parse #inst just fine

bronsa17:12:41

right, I was misremembering -- possibly you're using an earlier version when this wasn't the case

lilactown14:12:51

$ rebel-clj 'org.clojure/tools.reader {:mvn/version "1.3.2"}'
[Rebel readline] Type :repl/help for online help info
user=> (require '[clojure.tools.reader.edn :as edn])
nil
user=> (edn/read-string "1")
1
user=> (edn/read-string "#inst \"2010-11-12T13:14:15.666\"")
#inst "2010-11-12T13:14:15.666-00:00"
user=> (require 'clojure.edn)
nil
user=> (clojure.edn/read-string "#inst \"2010-11-12T13:14:15.666\"")
#inst "2010-11-12T13:14:15.666-00:00"

lilactown14:12:45

I’m basing this off of the example usage on the clojure.tools.reader lib anyway

kwladyka14:12:38

@thheller maybe stupid question, but how did you make shadow-cljs popular on the beginning of the story? How did you spread information to people about your project?

kwladyka14:12:33

Just thinking how to tell people about library, while it can’t be find in google on the beginning of the story 🙂

hmaurer16:12:43

Has anyone here used devcards with generative tests? If so, whast’s your setup?

dpsutton16:12:29

i don't understand why you would mix the two. Are you using devcards as your test runner? We only use devcards as a ui test

dpsutton16:12:33

We've used devcards as a tet runner for a little bit but switched to bruce's cljs test runner. Devcards had some issues with async tests and the cljs test runner is really just a test reporter and uses the normal testing to run so everything is supported

hmaurer16:12:37

@dpsutton yup I am using it as my test runner

dpsutton16:12:21

if you switch to https://github.com/bhauman/cljs-test-display i think you will enjoy it more. I think i remember with devcards you need to navigate to the card namespace to run those tests

dpsutton16:12:48

also the favicon and os notification features of cljs test display make it a real pleasure

hmaurer16:12:11

Ok, I’ll try that right away; thanks!

bhauman16:12:35

@hmaurer I absolutely agree with @dpsutton

hmaurer16:12:32

Haha, you might be biased

hmaurer16:12:36

My main reason to use devcards as a test runner was to have a visual interface to look at tests, and it seems like what you linked me provides just that

dpsutton16:12:12

yes. i think you will be tweeting about your better testing experience soon 🙂

hmaurer16:12:57

and for my generative tests, I would like to do something like “test passed if I can stest/check 1000 examples on my function and no error is thrown”

dpsutton16:12:59

also it should be trivial to drop in since devcards exposes the same deftest and is forms i think ? you just replace the require statement and should be up and runnin

hmaurer16:12:02

how can I express this with clojure.test?

hmaurer16:12:35

yup t does; I basically just need to figure out how to set this up with my shadow-cljs tooling, but it shouldn’t be too long

dpsutton16:12:51

i haven't used test check in anger

hmaurer16:12:31

ah, thanks!

hmaurer16:12:37

in anger? 😄

dpsutton16:12:49

in a real project versus just reading and poking in a repl

dpsutton16:12:18

also while you are doing this, if you are using figwheel-main you should look into extra mains. Running tests, devcards, and app simultaneously is a really nice way to work

frozenlock17:12:02

Is there a way to know which dependency is having big influences on the minified size?

lilactown17:12:49

@frozenlock if you’re using shadow-cljs, you can generate a build report: https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report

frozenlock17:12:10

Not using it 😞

kwladyka18:12:43

@frozenlock node modules? cljsjs?

kwladyka18:12:09

oh cljsjs is full size of the library, it can increase app very fast

kwladyka18:12:31

even if you use 10% of libraries files

lilactown18:12:57

cljsjs still gets run through Closure and should get dead-code eliminated

lilactown18:12:19

I found a stackoverflow asking this in April and it looks like the only answer was “use shadow-cljs” 😕

kwladyka18:12:00

Another solution is to use fighweel-main with {:npm {:bundles {"dist/index_bundle.js" "src/js/index.js"}}}

kwladyka18:12:10

I know only this two solutions

kwladyka18:12:08

https://github.com/kwladyka/form-validator-cljs/tree/doc here is an example of figwheel-main + clj as it is something new and not everybody know about it

kwladyka18:12:43

Everything else is automated, but this file has to be coded manually

frozenlock18:12:53

Thank you for the info

frozenlock18:12:54

I'm still on the old figwheel. I guess I should update anyway. I could use this as an opportunity to try shadow-cljs.

kwladyka18:12:13

shadow-cljs is cool tool too

frozenlock18:12:15

Wait... does shadow-cljs allow you to avoid relying on cljsjs?

kwladyka18:12:25

yes, both of this solution

kwladyka18:12:02

you shouldn’t use clsjs with them

frozenlock18:12:47

Interesting... well then, I know where my afternoon is going 😛

😅 4
lilactown18:12:29

yeah, cljsjs can still be used for externs but 90% of the time is irrelevant

lilactown18:12:26

also AFAICT even figwheel-main doesn’t give you any mechanism to get a fine-grained bundle size report

frozenlock18:12:55

I suppose lein-externs can do the job? (I already use it for library minified not on cljsjs.)

frozenlock18:12:13

Or are externs somehow irrelevant with shadow-cljs?

lilactown18:12:46

IME shadow-cljs does a really good job of externs-inference, but there are ways to configure it: https://shadow-cljs.github.io/docs/UsersGuide.html#externs

kwladyka18:12:59

I think you have better chance to find something which will show you node modules size

dnolen20:12:42

@lilactown not true that cljsjs goes through Closure

dnolen20:12:50

foreign libs never go through Closure, it cannot work

dnolen20:12:56

and it doesn’t matter what tool you use really

dnolen20:12:05

ClojureScript, Figwheel, or shadow

dnolen20:12:17

stuff that cannot survive advanced compilation just doesn’t work

dnolen20:12:45

to avoid any confusion the rule is simple

dnolen20:12:13

if you did not write it in ClojureScript, it cannot take advantage of Closure

dnolen20:12:38

the only other way is to write Closure compatible JS, like transit-js - but hardly anyone is doing that

dnolen20:12:19

so if you’re using something from NPM, or some random JS dep - it’s going to bloat your application, plain and simple

dnolen20:12:21

and nothing is going to fix that (at least not with Webpack or whatever)

dnolen20:12:40

maybe folks should be looking more closely at ClojureScript + https://rollupjs.org/guide/en

kwladyka10:12:18

this is very long doc. Do you know any example of using it with ClojureScript? Is it really worth to use it vs https://github.com/kwladyka/form-validator-cljs/blob/doc/src/js/index.js ?

kwladyka10:12:35

not sure how it differ vs example above

lilactown20:12:52

I think shadow-cljs runs npm deps through simple optimizations IIRC

dnolen20:12:40

which doesn’t do that much

lilactown20:12:41

but it’s definitely not standard

lilactown20:12:47

and yeah, there’s only so much you can do

dnolen20:12:12

the thing you really want tree-shaking only works in advanced