Fork me on GitHub
#clojurescript
<
2016-10-14
>
tianshu09:10:26

how to do same thing like this:

Flatpickr.100n.weekdays = [];

anmonteiro09:10:08

@doglooksgood is Flatpickr a foreign JS object?

anmonteiro09:10:37

(set! (.. js/Flatpickr -100n -weekdays) #js []) should work

anmonteiro09:10:52

well actually it won’t work because of the 100n prop

anmonteiro09:10:59

but it wouldn’t in JS anyway

anmonteiro09:10:41

you’ll probably need to use goog.object/set

tianshu09:10:43

I've seen a js file has this syntax. it is not a regular usage?

anmonteiro09:10:32

var x = {}
undefined
x.100n = 42
Uncaught SyntaxError: Invalid or unexpected token

anmonteiro09:10:58

that’s an L, not a 1

tianshu09:10:11

.............

tianshu09:10:26

you are right.

tianshu09:10:37

I need to change the font for my browser.

tianshu09:10:50

Thx, now I can continue my work..

robert-stuttaford12:10:40

so, i’ve got a weird preamble issue. reactDOM is being inlined before react, causing this funny error: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined

robert-stuttaford12:10:45

it’s only happening in one project. another project with the same versions, it’s fine

robert-stuttaford12:10:09

there is a key difference on this project: i’m using cljs’ :modules

robert-stuttaford12:10:32

infact, i’m not seeing the imul patch in the broken project either

robert-stuttaford12:10:04

lol. the preambles are reversed!

robert-stuttaford12:10:17

reactdom, react, imul in the one, and imul, react, reactdom in the other

robert-stuttaford12:10:09

faulty one is on the right

robert-stuttaford12:10:04

@dnolen i’m just making you aware of this ^; going to see if i can track the issue down in cljs now

robert-stuttaford13:10:28

should the preambles load in a specific order? i’m guessing yes, since cljsjs packages declare dependencies on each other

robert-stuttaford13:10:44

@martinklepsch have you perhaps encountered this behaviour?

martinklepsch13:10:01

@robert-stuttaford haven't seen this before. My guess would be that module resolution/ordering works differently when using :modules and the case of synthetic namespaces isn't fully taken care of

robert-stuttaford13:10:33

thanks Martin. what’s odd is that this is only happening on our build server. my mac, it’s fine.

robert-stuttaford13:10:04

i’ve scanned all the code where :modules appears, but nothing obvious jumping out at me. going to have to go deeper i guess

anmonteiro13:10:41

@robert-stuttaford would be interesting to see the logs between a normal vs failing build (with :verbose true)

robert-stuttaford13:10:59

will do — just tested with cljs 1.9.36 and the behaviour doesn’t exhibit there

robert-stuttaford13:10:26

not sure how old that version is, i’m guessing ‘quite'

anmonteiro13:10:48

can you reproduce it 100% of the builds?

anmonteiro13:10:09

@robert-stuttaford also, there have been a few versions between 1.9.36 and 1.9.229. it would also be interesting to track down the latest one that produces the bug

robert-stuttaford13:10:25

i’m doing a :verbose for the broken one now

anmonteiro13:10:29

I know I’m probably asking too much, no rush at all 🙂

robert-stuttaford13:10:35

it’s deterministic, insofar as it always happens on our CI box

robert-stuttaford13:10:39

with this version

robert-stuttaford13:10:10

is there a good place to see a list of all the released version numbers? i don’t mind trying some versions between here and there

robert-stuttaford13:10:50

seems like a handful

anmonteiro13:10:54

^ those have all been published to maven

robert-stuttaford13:10:10

could you give me a sense of what to look for in the verbose output?

anmonteiro13:10:32

sure. so the dependencies are compiled in order

anmonteiro13:10:04

so there should probably be something in the wrong order, comparing the 2 outputs

robert-stuttaford13:10:22

Adding remaining namespaces to :cljs-base

robert-stuttaford13:10:31

has adding entry [cljsjs.react.dom] well before adding entry [cljsjs.react]

robert-stuttaford13:10:53

i’m guessing that’s the output that confirms the symptom

robert-stuttaford13:10:01

running a ‘fixed’ build now

robert-stuttaford13:10:47

thanks for discussing with me, @anmonteiro 🙂

rovanion14:10:41

Hi! I was in here perhaps a month ago asking if anyone knew if it was possible to do interactive WebGL programming with cljs. Turns out its very much possible and I ended up writing a tutorial on the subject I thought I'd share: https://github.com/Rovanion/webgl-clojurescript-tutorial

rovanion14:10:54

Hopefully its of some use to someone!

bhauman14:10:02

Live rewind to the program state when a function was last modified http://dalsegno.ballingt.com/

bhauman14:10:24

Something like this would be possible in ClojureScript if we had stable compiled temporary variable names.

robert-stuttaford14:10:59

o/ bruce how’re ya goin!

robert-stuttaford14:10:48

doing great, thanks!

darwin14:10:47

@bhauman I think, this could be done on a library level, I can imagine a set of wrapper macros, which would read/store variables in some kind of db by name (instead of relying on global state), and that can be saved/restored with another set of functions

darwin14:10:35

he is speaking about resolving scope chain, I don’t fully understand this, but that could be done with js prototype chain cheaply

bhauman14:10:01

@darwin I'm thinking more simply

bhauman14:10:49

and in terms of the figwheel development workflow

bhauman14:10:27

but I'm not convinced that this has value

bhauman14:10:11

but you can add hooks to snapshot and restore your apps state, first and then have a system to record the apps state when changes occur and label those changes with the functions that changed

darwin14:10:55

yes, I think this could be useful in some scenarios, if figwheel provided a nice UI for managing those snapshots

bhauman14:10:15

rewind in general is powerful, and actually a simple rewind is possible with a library, as you say

bhauman14:10:49

but we don't want to redefine "defn" just probably add state snapshotting and restoring and UI... but this will only work for the most disciplined of apps. And most non trivial apps have to cheat with local state in their React Components.

bhauman15:10:23

and hence why it's not really a thing

darwin15:10:39

I think having some defn-like variant would be fine, user would mark functions explicitely

bhauman15:10:53

I disagree 😉

darwin15:10:27

ok, but making an app rewind-able is more effort than making it reloadable

darwin15:10:35

you need assistance from the developer

bhauman15:10:26

absolutely, and I'm thinking that is the main problem

bhauman15:10:55

there is serious effort involved, and a general solution will always kinda suck

bhauman15:10:27

hmmm, I'm coming around

bhauman15:10:28

I can see marking certain functions as code change <-> data snapshots as an interesting tool

bhauman15:10:53

but it would need to be explored to see if there is actual value there

bhauman15:10:10

it's hard to see it as an improvement on any change <-> data snapshot

bhauman15:10:47

and marking the snapshots with the functions that changed

darwin15:10:47

I think I just got a crazy idea, but only for ES6, which should be fine, under dev mode your could auto-wrap all clojurescript variables with ES6 proxy objects and redirect their reading/writing into that bag object I was talking about, thus effectively isolating all state (including the one closed over in closures) into one single flat object, and then you can introduce machinery for saving/restoring and managing history

darwin15:10:40

the price user would pay would be one or two steps of indirection when reading/writing values

darwin15:10:48

only in dev mode of course

robert-stuttaford15:10:02

when can i play with it? 🙂 this sounds fun!

robert-stuttaford15:10:30

sorry, that may have come across as rude 🙂 are you guys talking about the video of the js app that rewinds when you recompile code?

anmonteiro15:10:28

@dnolen @martinklepsch turns out what @robert-stuttaford mentioned above was indeed a compiler bug. Captured in http://dev.clojure.org/jira/browse/CLJS-1821 and patch attached

robert-stuttaford15:10:17

my goodness, that would be a fun thing to have in cljs

martinklepsch15:10:38

@anmonteiro @robert-stuttaford did you figure out why it happened on CI but not locally?

robert-stuttaford15:10:23

unfortunately, no

robert-stuttaford15:10:16

but this patch definitely fixes it in CI. applied and reverted the fix to make very sure

martinklepsch15:10:07

well, let's thank the weird CI behavior, you found a bug! 🙂

robert-stuttaford15:10:37

\o/ my first Cljs patch. only took me 4 years

si1415:10:26

am I right that right now there are only two sane ways to manage NPM deps: 1. CLJSJS and maintaining stuff myself 2. http://blob.tomerweller.com/reagent-import-react-components-from-npm ?

dnolen15:10:29

@si14 well CLJSJS isn’t NPM stuff 🙂 but yes the simplest way for the time being is to create a single foreign dep via Webpack or whatever

si1415:10:34

@dnolen yeah, it should be "CLJSJS route" really :) thank you!

dnolen15:10:54

@darwin last time I checked proxy objects were like 2-3 orders of magnitude slower than regular JS Objects - so might not be practical for many typical things

dnolen15:10:46

I was interested in them as well for Mori to provide idiomatic APIs

dnolen15:10:48

but unusable

dnolen15:10:27

(granted this was 2 years ago)

darwin15:10:50

hm, good point, more involved solution would be to instead generate wrapping code directly by compiler on each access site, but that sounds like a much more work and would break js-interop

dnolen15:10:24

@rovanion you might also want to take a look at @kovasb’s Gamma library, he did a pretty cool talk about it at StrangeLoop 2 years ago

dnolen15:10:32

@darwin without fast host level support Proxy I don’t think such ideas will go very far

nfisher15:10:33

@dnolen I might’ve missed it but is there any plans to have a bigdec equivalent in CLJS?

dnolen15:10:54

given that this needs to exist in all JS targets to be practical - I suspect we’re talking 5 years out at least

dnolen15:10:57

@nfisher Closure Library has a bigdec, if you mean support for that with regular arithmetic operators - also probably won’t happen for many years

dnolen15:10:13

there’s a multimethod like proposal for ES7 numerics which would make it practical

dnolen15:10:25

but without fast implementations in all desirable targets - useless

darwin15:10:31

@bhauman another avenue of exploration would be to try to leverage V8’s own code-patching functionality, it was added for DevTools to be able to live-edit code, they do something smart there I think, this could be a solution for replacing functions that were closed over and have no global entry-point to be redefined using eval https://github.com/v8/v8/blob/80caaac31bd05649ab81c0b84b320833c96b4ed7/src/inspector/v8-debugger.cc#L354 I could implement a support for this in Dirac

nfisher15:10:19

@dnolen mmm I was wondering if it could be backfilled w/ something like BigDecimal.js for now. Guess it still wouldn’t fit to the Clojure model though.

dnolen15:10:38

@nfisher we don’t need BigDecimal.js, Google Closure has BigDecimal

dnolen15:10:55

it has nothing to do with existence of an implementation - and everything to do with needing to overload + efficiently

dnolen15:10:48

but nothing is stopping anyone from making a generic math library for ClojureScript as a library

dnolen15:10:02

for people who don’t care about the 4X hit to normal integer math

nfisher15:10:38

Yea was thinking it’d be nice to have cljc calculations that are compatible in both Clojure and CLJS.

dnolen15:10:04

yes, it would be awesome to have a generic numerics lib where perf isn’t the primary concern

dnolen15:10:45

even better if somebody can prove that the modern JS perf story has changed

dnolen15:10:00

i.e. add methods that just call JS + will get inlined

dnolen15:10:17

I was unable to get desirable perf 2-3 years ago when I tried it

dnolen15:10:22

but maybe the story is different now

nfisher15:10:59

mmm yea for my use case perf is not critical but I understand there’s a lot of cases that would desire/require it to be performant.

dnolen15:10:22

if by a lot of cases you mean “all of ClojureScript"

dnolen15:10:34

ClojureScript would get 4X slower today with such a change

dnolen15:10:46

all the data structures assume lightning fast 32bit integer arithmetic

nfisher15:10:23

I guess I would be ok with saying “here’s” a special type and if I have to call custom methods to use it I’d be ok for consistency across both CLJ and CLJS.

dnolen15:10:48

@nfisher now you have a sense of why it hasn’t been done yet 🙂

nfisher15:10:14

Makes sense I figured there was a good reason for it.

nfisher15:10:33

Thanks for the clarification @dnolen 🙂

dnolen15:10:37

no problem

nfisher16:10:52

@dnolen sorry think I’m being thick but don’t see BigDecimal as a part of the Closure library? I assumed it would be goog.math?

dnolen16:10:35

@nfisher: oops I could have sworn there was one. Probably got confused by the presence of the arbitrary precision Integer type. Yeah appears to be missing.

rovanion16:10:53

@dnolen Did look at it but I have a ton of people with GLSL experience in my team so I didn't want to throw them off even more than I've already have by putting them on cljs.

rovanion16:10:47

But perhaps I've discarded it too quick. Can't recall if I've seen the talk.

witek16:10:39

Hi. I have included figwheel to an existing reagent app. Starting lein figwheel works without errors. Sadly the init! function is not called in my core.cljs. Any ideas what the reason could be? Thank you!

nfisher16:10:50

@witek can you share your cljsbuild section in a gist?

nfisher16:10:37

Well probably your whole project.clj

witek16:10:05

@nfisher I got it. I forgot to include my dev.cljs which calls the init! function. Thanky you!

darwin17:10:42

can anyone point me to a recursive-macroexpand implementation? I need macroexpand which walks a form and applies macro-expansion to all nodes (top-bottom)

anmonteiro17:10:58

@darwin doesn’t macroexpand-all exist?

anmonteiro17:10:20

oh it’s in clojure.walk

darwin17:10:38

@anmonteiro thanks, I didn’t look into clojure.walk 🙂

darwin17:10:15

that is how I would implement it, using clojure.walk, but didn’t want to reinvent the wheel 🙂

savelichalex17:10:00

how I can get function name in macros?

dnolen17:10:24

@savelichalex what do you mean?

savelichalex17:10:55

let's explain I have function (defn foo []) and I want to get foo

dnolen17:10:06

@savelichalex this still isn’t enough information to know what you mean

dnolen17:10:20

what are you trying to do?

dnolen17:10:29

analyze all the symbols in the body of macro? something else?

savelichalex17:10:02

no no, I don't know how calling this right

savelichalex17:10:29

just when I create it through defn this is called var, right?

dnolen17:10:55

yes though the meaning is different in ClojureScript which doesn’t have real vars

dnolen17:10:09

this discussion will be much simpler if you give some example simple macro that you are trying to write

savelichalex17:10:31

Of course, just give me a sec

dnolen17:10:51

resolve-var isn’t a thing in ClojureScript outside of the analyzer API

dnolen17:10:13

you don’t need to bother with :meta, just access the name via :name

darwin17:10:31

@savelichalex what about something like this? https://github.com/binaryage/dirac/blob/master/src/automation/dirac/automation.clj#L43 in defscreen you can call get-component-name passing it (meta #'~screen-component)

darwin17:10:04

and get-component-name should be a normal function looking at the data and extracting name:

savelichalex17:10:14

@dnolen @darwin thanks a lot! that's work now)

darwin17:10:36

ah maybe that’s maybe not what you wanted to do, my solution extract metadata to cljs land (to be used at runtime)

savelichalex17:10:37

@darwin but I want to use get-component-name in cljs code

darwin17:10:49

you wanted to do all on macro side I guess

darwin17:10:41

now when I think about it more, your solution also extracts the var metadata to cljs (if ~(resolve-var &env component) was correct), so if you are ok with that, you can replace ~(resolve-var &env component) with #’~component I believe

darwin17:10:56

but ultimately you want to resolve it at compile-time I believe, so generated cljs code contains just the name baked-in

savelichalex19:10:29

@darwin hm, i'm using it in runtime too. Can use explain what #'~ do please?

darwin19:10:04

@savelichalex I can’t explain, it is just magic I use, my understanding is it that it gives you var-like thing for given symbol 🙂

darwin19:10:22

in clojure #x is a special shortcut for (var x)

savelichalex19:10:29

@darwin heh, well, then I just remember this))

darwin19:10:01

AFAIK, in cljs there are not full vars, so this emulates var for cljs

savelichalex19:10:19

but if I understand right var is not working

darwin19:10:09

there are var-like structures, but they are not fully compatible

darwin19:10:27

I have done little clojure, so for me cljs is the standard, and clojure is divergent 😉

darwin19:10:32

and those var-like structures are available only in macros, but nothing is stopping you “emit” that data to cljs side, to be used at runtime

savelichalex19:10:33

ahah, great point!)

darwin19:10:06

that is what we are doing there, but you must be careful, you don’t want to mindlessly dump whole compiler state into generated js 😉

darwin19:10:31

you want to cherry-pick only stuff you need, ideally

darwin19:10:22

I may be wrong of course, this is a bit blurry area for me, I used it only for test infrastructure, so I didn’t care that much

savelichalex20:10:34

guys, I need help again) I use get-component-name in function, that iterate through vector with map and it's return local variable name. What I'm doing wrong?

savelichalex20:10:22

I choose @dnolan solution for macro

(defmacro get-component-name
  [fn]
  (-> (resolve &env fn) :name str))

darwin20:10:05

in defscreen you have to extract metadata from original symbol used, and pass it down the pipe

darwin20:10:38

currently you are getting the name of screen symbol, which is of course “screen"

savelichalex20:10:18

Does this mean that I can't get real function name?

darwin20:10:16

depends what do you mean by function name, AFAIK defn is just a sugar for (def … (fn …)), so your functions have technically no name

darwin20:10:24

we were speaking about var names all the time

darwin20:10:58

think about this: `(defn a [] “I’m a”) (def b a)` what should (defscreen b …) see as function name?

savelichalex20:10:44

Looks like they see name of var b

darwin20:10:17

the question is if this is what you wanted

savelichalex20:10:22

Ok, this is mean that var is somehow "linked" with fn

savelichalex20:10:36

Maybe I can save it to this fn

savelichalex20:10:03

And then use that saved value

savelichalex20:10:22

@darwin what do you think, this is possible?

savelichalex20:10:40

smth like in meta for this fn

darwin20:10:33

you can attach metadata to vars, not sure about functions

savelichalex20:10:32

Or I can create map with it in defscreen and use then... 😄

rovanion20:10:37

A function is just a value like any other right?

darwin20:10:38

@savelichalex it is possible to attach metadata to functions, I just tested it in planck

savelichalex20:10:03

@darwin What about add, not create with meta

darwin20:10:30

both things work, attaching meta to fn, will turn in into MetaFn (implementation detail)

darwin20:10:45

alter-meta! ?

darwin20:10:14

or maybe vary-meta?

savelichalex20:10:55

(alter-meta! #'foo assoc :test "test") should work 🙂

mathpunk21:10:23

Can someone help me diagnose how I'm using atoms wrong in clojurescript? The error is No protocol method IDeref.-deref defined for type cljs.core/PersistentArrayMap, the line is https://github.com/mathpunk/anansi/blob/master/src/cljs/anansi/reading/app.cljs#L19

mathpunk21:10:49

what's odd is, i was referencing this data just fine a moment ago, and i can't tell what's changed

mathpunk21:10:14

thinking i might not understand when to clj->js and vice versa (if there is a vice versa)

jrheard21:10:37

@mathpunk - at what point is data made into an atom?

jrheard21:10:17

i think you’re doing @data when data looks like {:foo :bar} rather than (atom {:foo :bar})

mathpunk21:10:53

and that's what i left out as i changed the definition of state, thank yew

spiralganglion22:10:14

Let's suppose I'm about to make a spiffy CLJS webapp with a WebGL-based GUI. Is there a particular WebGL library that you, great CLJS community, are most fond of? I've taken a look at a handful, and Karsten Schmidt's http://thi.ng libs really stand out, but I worry about taking a dependency on something (his "geom" lib) that's prominently marked as "BETA"/pre-release, and has only seen a handful of updates in the past year. Thoughts of the wise Clojurians?

spiralganglion22:10:57

If the situation is dire, I'll just write the WebGL abstractions I need to make ends meet. But if there's a nice lib, I'd much rather benefit from the efforts of those who have made this journey before.

jrheard22:10:46

might have relevant thoughts/advice

jrheard22:10:07

https://github.com/kovasb/gamma was mentioned as part of that discussion