Fork me on GitHub
#clojurescript
<
2016-07-26
>
micha00:07:18

hi all, feedback on this would be greatly appreciated: https://gist.github.com/micha/f3d9d932d8530838698a77156db0be3a

micha00:07:56

want to get bound-fn functionality in cljs there

micha00:07:34

use of js* and eval() seems sketchy, there must be a better, more efficient way to do that

dnolen12:07:46

@micha: there's just no way to make something like bound-fn work properly without fundamental ClojureScript support

dnolen12:07:29

there’s already open tickets for it but there’s no chance I will consider it until after the cljs.spec port stuff ships in a release

micha12:07:52

@dnolen thanks I'll check the tickets, but it does seem to work. which part needs cljs compiler support?

dnolen12:07:49

@micha it may not, but why do you need eval?

dnolen12:07:06

if you need eval it usually means something needs to solved in some deeper way

micha12:07:48

yeah that part is gross. i needed to resolve a js variable at runtime

dnolen12:07:35

anyways there’s no simple way to do it correctly without hiding all the details in ClojureScript itself if it’s going to happen

dnolen12:07:44

but super low priority for the reasons stated above

micha12:07:24

sure, that's why i made it a library, so i can play around with it without changing the compiler

dnolen12:07:54

@micha if you were just looking for feedback on your library then carry on 🙂 nothing to add!

micha12:07:48

I'm not even sure bound-fn is a win yet, depends on how it affects performance in a real application

micha12:07:10

there is a cost to using this form of binding even if you don't use bound-fn

micha12:07:03

but yeah i was hoping someone would see a cleaner way to do the eval part

dnolen12:07:40

@micha also I guess you don’t care about advanced optimizations?

dnolen12:07:01

things will get renamed and anything inside of eval is not something Closure is going to look at

dnolen12:07:53

(people have requested bound-fn for 5 years and I’ve yet to see a proposal that I’m particularly excited about)

micha12:07:56

it will warn if you don't declare the dynamic var as ^:export

dnolen12:07:13

ok so you’ve exported it

micha12:07:54

yeah it's a trade-off for simplicity

micha12:07:32

i could compile thunks in the binding macro instead

micha12:07:47

thunks that set the var

micha12:07:22

not sure how I'd restore previous bindings that way though

micha12:07:15

@dnolen is the output of cljs-in-cljs suitable for optimization in Google closure?

dnolen12:07:49

@micha no advanced optimizations is probably impossible

dnolen12:07:14

I haven’t seen anyway to make it work, the compiler needs to look up vars and namespaces

dnolen12:07:30

so Closure advanced optimization collapsing is out of the question

dnolen12:07:26

you could off course put the output of the boostrapped compiler through advanced optimizations

dnolen12:07:36

but pretty sure that’s not what you’re asking

micha12:07:41

i was interested in it not so much for runtime eval as macros in cljs

micha12:07:03

yeah that's what I'm interested in

dnolen12:07:55

right if you want macros you have to be OK with 8-10mb of JavaScript pre gzipping

micha12:07:34

but i could run that through gcl then right?

dnolen12:07:42

I already said that above

dnolen12:07:55

it’s 8-10mb with Closure simple optimizations pre gzipping

dnolen12:07:10

(or maybe I’m forgetting and it’s 2.5-3mb?)

dnolen12:07:15

with simple optimizations

micha12:07:16

i mean the output of the bootstrapped compiler, without runtime eval

dnolen12:07:06

the bootstrapped compiler is same compiler

dnolen12:07:04

Closure itself can run only in JavaScript, I mentioned this the other day - you could have a fully JVM-less pipeline right now granted you have time and interest to wire everything together

micha12:07:33

writing macros in cljs would be interesting because the macros could use cljs multimethods, etc

micha12:07:04

yeah that's awesome, I'll work on a boy task to do it

micha12:07:12

i mean boot

micha12:07:22

autocorrect

dnolen12:07:02

to be clear you can’t write macros in ClojureScript w/o bringing the entire compiler with you (not sure I communicated that)

micha12:07:29

at runtime too? or just during compilation?

dnolen12:07:41

you need it at runtime

dnolen12:07:02

compilation isn’t good enough since macros often mix runtime stuff in

micha12:07:06

surprising!

dnolen12:07:17

well it shouldn’t be 🙂

micha12:07:20

lisp is deep

dnolen12:07:26

this is why macros don’t exist in ClojureScript files!

dnolen12:07:35

since day 1

micha12:07:38

very interesting

micha12:07:08

i see it now

micha12:07:12

compiler macros basically guarantee no runtime dependency on the compiler

micha12:07:59

man lisp is such a finely balanced thing

dhucerbin14:07:05

I'm affraid I don't understand it fully. Could you give an example?

cmcfarlen14:07:51

I'm having an issue with transit-cljs. I am reading a Number value from a form (using cljs.reader/read-string) and sending it to the server which is expecting a float. If the Number is decimal (i.e. 1.12) then the server gets a float. If its is a whole number (i.e. 1 or even 1.0) then the server ends up with a long. This happens even if I cast to a float on the client. Is there a way to force transit to send a decimal type? I use transit/bigdec for money which works fine, but there isn't a transit/decimal.

dnolen14:07:38

@cmcfarlen: there’s no way to force it

dnolen14:07:08

@dhucerbin: macros can depend on runtime stuff, simplest case is previously defined functions

dnolen14:07:48

in Clojure people do that all the time

dhucerbin14:07:58

Huh, I was thinking about it backwards. Thanks!

cmcfarlen15:07:02

@dnolen: thanks. Would you recommend using a tagged value in this case to coerce to a float or normalize to bigdec?

dnolen15:07:51

@cmcfarlen: yes that’ll be simplest

cmcfarlen15:07:29

@dnolen: yes, that was easy and works great. Thanks! Transit is good stuff.

pvinis18:07:23

how should i use cljs->js? i get a “use of undeclared cljs->js”..

pvinis18:07:46

using re-natal with reagent

jr18:07:13

clj->js

dimovich18:07:41

what libs would you recommend for animating the ellipses in the background: https://drive.google.com/file/d/0BzfCuz894WQcV2I4RHNuMjB2ZTQ/view

dimovich18:07:03

looking now at fabric.js

dimovich18:07:16

but maybe there is some simpler way...

pvinis19:07:04

so in re-natal, in the sample app, if i wanna set the greeting when pressing the button, i would call (dispatch [:set-greeting “bla”])?

pvinis19:07:39

i mean is that the way to do it. i know it works, but is that the “cljs/re-natal/reagent/all that” way?

pvinis19:07:44

also, i want to have persistent storage of the db, so i keep the greeting after app restart. i found AsyncStorage. is there an example of usage with re-natal?