Fork me on GitHub
#clojurescript
<
2016-07-08
>
blance00:07:46

is there a good way to debug in production (i.e. everything works in figwheel, but foreign libs cannot be found when doing advanced optimization)

denisj04:07:19

FYI: some early testing with 1.9.93 have issue in Chrome devtools with seeing cljs source & (js-debugger) doesn't breakpoint whereas 1.9.89 is fine. Using dirac on Canary/Unstable so I'm yet to confirm this is an issue in plain devtools

mikethompson06:07:56

@blance: so that sounds like an externs issue? Are you familiar with the challenges around externs and advanced compilation? If not, see: https://github.com/cljsjs/packages/wiki/Creating-Externs

mikethompson06:07:35

This is no way a solution, but the code generated by :advanced compilation becomes slightly easier to understand when you use this setting: :pseudo-names true https://github.com/clojure/clojurescript/wiki/Compiler-Options#pseudo-names

mikethompson06:07:34

also use :pretty-print true Remember to remove both options when you have solved the problem.

jjunior13006:07:27

Which data transformation library is most popular in ClojureScript development? Not interested in Clojure. • Spectre - https://github.com/nathanmarz/specter • Instar - https://github.com/boxed/Instar • balagan - https://github.com/clojurewerkz/balagan • Other Which one do you use, and why not one of the other ones? Spectre looks good but it only works for me on Clojure and not ClojureScript. Even though it says it's for both. Haven't tried the rest.

rauh06:07:41

@jjunior130: Since you ask: I use cljs's core and datascript. I'm very picky with pulling in dependencies into my cljs code. I only have datascript, rum and nothing else. I'd probably not use specter in cljs (even though I love it in clj) because it's a pretty large dependency and has been growing a bunch.

jjunior13006:07:55

@rauh: thanks for datascript. I'm gonna study it. Edit: sorry for sharing, meant to reply, assumed share button was reply button, clicked it before reading, share button should like like https://cdn3.iconfinder.com/data/icons/glypho-free/64/share-128.png

rauh08:07:59

PSA: In case you have React :key warnings frequently, the new React v15.2 gives much nicer error messages about them.

darwin08:07:08

@denisj please confirm it in plain devtools, in case of Dirac issue I could look into that

denisj08:07:17

@darwin: will do, probs tomorrow

martinklepsch09:07:46

@rauh: when you say "large dependency" — isn't that a non-issue with advanced builds because of dead code elimination?

rauh09:07:59

@martinklepsch: DCE isn't as magic as I thought. A lot of code will still end up in your build even if you don't use it. Depends on the library's code of course. Simple functions will get DCE, but many libraries are more than simple fns.

rauh09:07:15

In my example I had garden and datascript somewhere required (BUT never used/called). It was still all there even with advanced builds. I wouldn't blindly rely on DCE, better double check.

martinklepsch09:07:20

I see. Guess I should integrate my boot task to gzip and show sizes into our production build pipeline :

rauh09:07:05

@martinklepsch: I did that recently in my build script and I log (simple spit) the size after every advanced compile: https://gist.github.com/rauhs/2a02e5e04b5bd4e4b4b5

martinklepsch09:07:55

made this a while ago but adding an option to log the sizes is neat, also brotli 👍

nathanmarz09:07:18

@jjunior130: happy to help in #C0FVDQLQ5 channel with whatever issues you ran into using specter in clojurescript

dnolen12:07:36

@rauh DCE is not really about simple/complex fns - all that stuff will DCE

dnolen12:07:55

but there are many library anti-patterns that will defeat it - that includes top level data structures

dnolen12:07:15

@ethangracer: no we do not support that and unlikely to

rauh12:07:04

I didn't mean to say "simple vs complex fns" but "simple fns" vs "non-fns (such as top level data structures)".

rohit13:07:04

For anyone interested, this talk on BuckleScript (OCaml -> JS) is pretty good. https://www.youtube.com/watch?v=8GNUh1TYfo8

misha15:07:18

@dnolen: is there any performance benefit of using named functions over anonymous ones? e.g. will extracting #() out of React component's render function reduce any execution overhead (like redefining the same #() on each render)?

(rum/defc yo []
  (text-input {:on-click #(...)}))
==>
(defn on-click ...)

(rum/defc yo []
  (text-input {:on-click on-click}))

dnolen15:07:50

@misha not enough to matter for event handlers

misha15:07:31

so it is basically code-style decision, right?

dnolen15:07:24

for really critical stuff, yes there is a cost to using anonymous fns on most JS VMs

dnolen15:07:11

but even the finest grain user generated event handlers aren’t going to fire more than a couple hundred times a second

misha15:07:27

so critical, that 60 renders/s is not critical enough in comparison?

dnolen15:07:55

by critical I mean more like something like 1000000 times a second at least

misha15:07:48

do you have a top of the head example of such a usecase?

dnolen15:07:59

ClojureScript internals

dnolen15:07:54

internally we try to avoid closures but I can’t remember ever seeing that be the bottleneck in any application level event handling code I wrote

misha15:07:33

thank you

akiel15:07:00

Hi, I like to use window.msCrypto but the advanced compiler minifies msCrypto. I already wrote an externs file but it doesn’t work. Should externs work for window?

dnolen15:07:23

window is the global context

dnolen15:07:26

you don’t need that

dnolen15:07:32

var msCrypto = …

akiel15:07:43

window.crypto is not minified

dnolen15:07:06

what does and doesn’t get minified isn’t under your control (except through externs)

dnolen15:07:14

there’s all kinds of heuristics

akiel15:07:58

my code: (let [crypto (or js/window.crypto js/window.msCrypto)) the minified version: var a,b=window.crypto;a=r(b)?b:window.qm;, the externs:

var window = {
    "msCrypto": {}
};

akiel15:07:04

is my externs ok?

rohit15:07:01

@akiel: try: var msCrypto = {}

akiel16:07:59

@rohit: I’ll do - wait for compilation

jonas16:07:21

@misha: I think one problem with #(…) is that it will make many “automatic” implementations of shouldComponentUpdate trigger unnecessary re-renders

akiel16:07:03

Thanks @dnolen and @rohit it works

johanatan17:07:08

did anybody see that tweet of a little snippet of elisp for making emacs to consider keywords as one word when in evil mode?

johanatan17:07:24

[i have misplaced it and would love to know it so i can apply to my emacs]

isak17:07:42

is there a way to request an updated package from cljsjs?

rohit17:07:41

@isak, best to discuss on #C0E66E1H7

hueyp18:07:10

if I want to make a js class … is it legit to use defn + specify! on the prototype, or am I relying on impl details?

blance18:07:40

Is there a way to not load/access forign-libs from global? The big JS project I have has some kind of script loader, which I would use to load the compiled cljs->js code. However, it would do closure around it to avoid exporting anything to global. Thus my cljs code won't be able to do (.func js/some-libs) cuz none of the foreign libs will live under js/

hueyp18:07:36

@rohit: awesome, thanks — glad to see the verbose way is legit 🙂

anmonteiro18:07:50

@hueyp: deftype would be the most idiomatic depending on the stuff you need

hueyp18:07:31

@anmonteiro: thinking of a case where I want to ‘inherit’ a third party prototype (not sure the right word) … but I agree ya, deftype works for that 🙂

hueyp18:07:35

the gist example

limist18:07:57

Advice needed please: I'm trying to recover the name of a function being passed around, with

(meta (var the-function))
...which works in a cljs REPL, but when compiling, I get the error message java.lang.AssertionError: Assert failed: (ana/ast? sym) Any way around this?

jr19:07:29

vars are only supported at compile time in clojurescript. you might be able to demunge the name of the fn instance

jr19:07:59

something like

cljs.user=> (demunge (.-name foo))
"cljs/user/foo”

darwin19:07:11

demunge won’t work under :advanced builds

darwin19:07:36

In one of my project I was able to retrieve var’s meta in macros and bake it into cljs sources as data, I used it in test environment with dev builds, but I don’t see a reason why it should not work under :advanced builds as well

johanatan22:07:41

suppose I have a map with certain keys and a vector of special keys. what's the best way to duplicate every k/v in the map with the new special keys mapped to the respective values. so, like rename-keys but keeping the old as well as the new. I'm thinking (merge old (rename-keys old new)) where new is a mapping from the old keys to the new 'special' keys mentioned in my initial vector above. [not the best performance since the 'merge' will be throwing away a lot of duplicated values].

johanatan22:07:06

also, a for comprehension over the original map would probably work.

johanatan22:07:17

[and be a lot better performing]

johanatan22:07:23

anyone have other ideas?

johanatan22:07:15

[oh, i suppose I could remove all non-special keys from old before passing it to rename-keys to eliminate the perf issue i mentioned with merge above]

johanatan22:07:33

i.e., do a dissoc of the non-intersecting keys

xcthulhu22:07:42

Hey all! This is probably a n00b question, but I have a function which transforms milliseconds since epoch to an #inst:

(defn ms-inst
  "Convert milleseconds to an #inst (inverse of `inst-ms`)"
  [msecs]
  #?(:clj  (java.util.Date. ^{:tag ~'long} msecs)
     :cljs (js/Date. msecs)))
I feel like this is some built-in I've overlooked...

johanatan22:07:11

actually to back up one level and ask my original motivation for the above: does anyone know of any clojure[script] code which automatically adds "-webkit-xxx" attrs for any standard attrs where there is overlap?

johanatan22:07:27

[can't imagine that every person out there would want to implement this for themselves]

johanatan22:07:39

[and also I'm using re-frame/re-con/reagent if that matters]

akiva22:07:03

@xcthulhu, there aren’t any time functions built into clojure.core. But you can use cljs-time and clj-time to wrap the Joda Time library. That could be overkill if that’s the only timestamp manipulation you need.

akiva22:07:36

Ah, it’s 1.9. I haven’t messed with 1.9 at all yet.

xcthulhu22:07:26

@akiva: It looks like functionality from clj(s)-time is creeping in to Clojure 1.9 btw https://github.com/clojure/clojure/blob/master/src/clj/clojure/instant.clj

akiva22:07:33

Innnnnnnteresting.

akiva22:07:39

Actually, looks like the clojure.instant namespace has been available for awhile. [cue The More You Know jingle]

blance22:07:19

Does anyone know why I get myname_space is not defined when doing simple compilation, while advanced don't have this error?

johanatan22:07:42

this is what I came up with (if anyone sees room for improvements):

(defn wk [styles]
  (let [attrs [:flex :flex-flow :align-items :align-self]
        mapping (zipmap attrs (map (fn [a] (keyword (str "-webkit-" (name a)))) attrs))]
    (merge styles (rename-keys (select-keys styles attrs) mapping))))

johanatan22:07:52

[attrs is of course non-exhaustive at this point]

limist22:07:11

@jr @darwin Thanks for the ideas/pointers; I'm concluding it's too bothersome to recover the function name, so I re-designed the abstraction to not need it.

darwin22:07:12

@denisj: I can confirm a bug in plain devtools, they don’t load sourcemaps on first load sometimes, you have to refresh the page second time to make it work (my experience)

darwin22:07:02

I have experienced it with some test code when developing Dirac

denisj22:07:44

yes same, different issue. Refresh as often as you want, no cljs with 1.9.93

denisj22:07:31

And in my case it is served over localhost via figwheel

darwin22:07:38

well, wait, in my case, the cljs file is not even listed in the files panel on the left

darwin22:07:44

yours looks different

denisj22:07:45

All my cljs files are listed and followed with &rel= numbers but no content

darwin22:07:56

if you have reproducible project, you can try to bisect clojurescript commits between 1.9.89 and 1.9.93

darwin22:07:04

should not be that many commits I guess

darwin22:07:30

AFAIK dnolen touched some source-maps related code between those versions

dnolen22:07:33

@denisj what source map options are you using?

dnolen22:07:41

also 1.9.93 is not an official release

denisj22:07:45

So you are confirming you also don't see cljs source but in your case not event the files are listed in left sources pane.

darwin22:07:54

@denisj now when I think about it more, my case was a different bug, it was devtools not recognizing there is a source map associated with a js file, so files panel didn’t even show the cljs file(s)

denisj22:07:07

@dnolen: :source-map true :source-map-timestamp true :optimizations :none

darwin22:07:07

your case looks like devtools is not able to fetch content of the source map

dnolen22:07:58

in anycase I would stick with 1.9.89 for now

denisj22:07:09

will do, just thought I'd report.

dnolen22:07:13

I’m also only interested in the issue outside of all these other things

dnolen22:07:21

not interested reports involving other stuff

dnolen22:07:42

if you can repro by itself then open a JIRA ticket

dnolen22:07:01

will get it sorted with along the batch of clojure.spec porting stuff in my queue

darwin22:07:15

@denisj: if you can provide a simple repro repo, I will look into that and debug why devtools does not work in that particular case, that could pin-point the issue for dnolen

darwin22:07:41

if it worked in .89 and stopped in .93, that smells like a regression

dnolen22:07:17

yes there were some tweaks to support loading source maps in non-localhost scenarios

dnolen22:07:37

so there might be an issue with those changes

denisj23:07:47

fyi: I just tested with local file via file:// and same problem