Fork me on GitHub
#clojurescript
<
2017-05-03
>
aisis01:05:19

Anybody know any libraries for three.js?

aisis01:05:30

What are some libraries to look at for webVR/webAR?

john01:05:13

@aisis I'm pretty sure there are three.js cljs wrappers. Or at least libs inspired by it. c2 or c3? Something like that. I haven't heard about any webVR/webAR libs in cljs yet.

john03:05:19

is it possible for a library to inspect a downstream project's project.clj?

danielcompton05:05:25

john: lein-npm does this as one example.

john05:05:59

I was needing a pure cljs capability. Like a plain lib. Not a plugin.

john05:05:37

There were a few other leads, like using &env in a macro, but I couldn't get that to return the user's ns in cljs

john05:05:47

but I appreciate the help!

dominicm17:05:27

I think macros are the correct way to get the user's *ns* value.

dominicm17:05:31

It's how tools.logging works for example

john18:05:30

I'll try ns

john18:05:40

eh, \ns\

john18:05:38

but your suggestion reminded me of another macro I already had that used ~(name cljs.analyzer/*cljs-ns*)!

john03:05:59

I need to get at the :main compiler option when available

tbaldridge03:05:37

project.clj is an artifact of lein

tbaldridge03:05:15

so no...as the downstream project may not even use lein

john03:05:01

well, the main is in the compiler map, which gets passed to the clojurescript compiler, right? Any chance it's hung onto in there somewhere?

john03:05:31

(whereever that is...)

john03:05:02

oh good point about the downstream maybe not even using lein

hagmonk03:05:32

in reagent, what is the idiomatic way of handling a component that is waiting for data to come in? Do you just return an empty vector until you see the data turn up in the ratom?

john03:05:30

the ratom should automatically trigger the component to deref the ratom when the ratom takes on a new value

hagmonk03:05:18

right, but I have some js interop that calls into metricsgraphics to trigger a graph render … I want to skip doing that until the ratom contains something useful

hagmonk03:05:06

I certainly believe a conditional will work, I just wondered if there wasn't a more elegant way than putting a conditional in every component

john03:05:25

passing in empty vectors in a loop would just hang the main thread. There'd be no way to know when to stop. I don't think it's possible to do what you're suggesting.

tbaldridge03:05:04

@hagmonk no, and that's one of the things I don't like about the reagent model. There's no way to signal "don't even try to render this until you have all the data I need".

hagmonk03:05:53

@tbaldridge a conditional it is then! 😬

Oliver George03:05:13

@tbaldridge I've been wondering about that. How does Om.Next handle a situation where the data takes a long time to come back? Seems like it would cause a UI freeze.

Oliver George03:05:48

The alternative is a pain. Something like "check data and show loading" logic in views. At least that gives you the choice of what to show while waiting.

tbaldridge03:05:10

That's really the only two options, require it in every component, or at a global level define a "loading" indicator and then load all your data at once.

john03:05:10

@olivergeorge have you used Om? What UI freeze situation are you talking about?

tbaldridge03:05:50

that "freeze" happens in any model though, it just looks different. In reagent it was a thing where the frames of your controls would pop up but be empty, then after a few seconds populate with data.

john03:05:34

In general though, the whole idea of the reactive model, in both reagent and om, is that things aren't supposed to freeze because all components get their data asynchronously

tbaldridge03:05:39

well define freeze

tbaldridge03:05:06

any async system has as a "pause" time, that's the whole thing with async code....do something...pause....do something

tbaldridge03:05:32

So it's really a question of how you want to handle missing data...in the render hander of every component? Or at a global level. I got tired of the reagent model in the app I worked on. If an error, or a bug never put data in to the ratom, you just got a blank control.

john03:05:56

ah, I thought @olivergeorge was referring to hanging the main thread.

melindazheng03:05:17

Calling all fellow Singaporean Clojurians, please search #clojure-sg to join Singapore Clojure slack channel, we have regular Singapore Clojure Meetup monthly, do come and join us. 😊

hagmonk03:05:21

also main thread is the only thread 😬

john04:05:48

hah I've probably been working with web workers too much 😉

Oliver George06:05:41

@tbaldridge Yeah, we don't love all the "loading" checks with reagent. I guess a top level "loading" handler is reasonable. Real worry is UI reflecting past state while it waits (e.g. save button can be clicked repeatedly while data is sent).

dmitriid07:05:23

Hi all. A very newbie question 🙂 I’m trying to figure out :advanced compilation woes 🙂

dmitriid07:05:35

Given this project:

dmitriid07:05:21

When I run lein cljsbuild once min, it produces a 145 kB file that only contains minified React, React-DOM and Math.imul

dmitriid07:05:30

And I can’t for the life of me figure out why 🙂

dmitriid07:05:43

Googling/StackOverflowing doesn’t help either 😞

dmitriid07:05:31

Aaand found the answer myself 🙂

ERROR: JSC_MISSING_PROVIDE_ERROR. required "trak.action_handlers" namespace never provided
Which led me to http://stackoverflow.com/a/43363113/445049 > Dashes from namespace names need to be replaced with underscore in the file name.

tomaas09:05:05

hi, is there any plugin for emacs doing something similar to eslint, I mainly want emacs to show me unused definitions

tomaas09:05:35

I can't see how this could be achieved with clj-refactor and cider neither does this, at least for me

dmitriid11:05:00

Another newb question I seem to not find a proper answer to: how do you store separate dev/staging/production configs for your ClojureScript apps? Like API keys, FB app ids etc. etc. I could store them in :profile, but I don’t want to commit them to git. And I don’t really want to pass them as a long string of env variables.

mrchance11:05:06

dmitriid: Not sure, but you can have a separate profiles.clj file next to your project.clj that can contain these things and which you don't need to check in.

dmitriid11:05:51

hmmm…. that might work 🙂 I have to check it out. Thanks!

dmitriid11:05:35

The question remains of how to get these values 🙂

mrchance12:05:13

Depends on what your setup in general is

dmitriid12:05:41

What I meant is: how do I then get the values from :profile into my code? 🙂

dmitriid12:05:09

the usual suspects like cprop fail during compilation

timgilbert12:05:28

One approach I’ve seen people take is to have a macro that defines a big map by reading in an EDN file with a macro

timgilbert12:05:31

But keep in mind that all your values are visible to whoever can view your compiled source code, so using values directly might not be the best solution if your data is too sensitive for git

rauh12:05:53

I just use a macro:

(defmacro config
  "(config :foo :bar)"
  [& korks]
  (let [c (:shared (nomad/read-config (io/resource "config/main.edn")))
        c (cond-> c (seq korks) (get-in korks))]
    `~c))

rauh12:05:01

Which makes sense since it's often that you share config for server/client.

dmitriid12:05:17

Once again, the macro only reads a single hardcoded config 😉

dmitriid12:05:23

Thing is, it’s not just config values such as API keys etc. Your code (like logging to console) may very well depend on env variables etc.

rauh12:05:53

Not sure what you mean. Can you make an example?

rauh12:05:39

You can refer to "secret" files in nomad. That aren't checked in. Then you can set default values for dev setup.

rauh12:05:59

And you can set different values depending on the environment. Staging etc etc.

rauh12:05:22

Settable in proejct.clj by "-Dnomad.env=dev"

rauh12:05:01

;; This loads the secrets. NOT in git :)
 ;; Contains all :cfg.secret.... keys
 :nomad/private-file #nomad/file "/var/secret/etc/srs.edn"
;; /var/secretc/ is an encrypted volume.

dmitriid12:05:39

By hardcoded I mean this in your example:

(let [c (:shared (nomad/read-config (io/resource "config/main.edn")))
"config/main.edn" is hardcoded

dmitriid12:05:26

Examples depending on config: - disable console.log in production mode - access different API endpoints based on build: dev/stage/production - access/retrieve assets from different endpoint based on build etc.

dmitriid12:05:53

/me is looking into nomad now

rauh12:05:15

Look into nomad yes. That's all covered by it.

rauh12:05:09

Though nomad covers it, nothing is preventing you form a (case (System/getProperty "my.var") ... and load different config files.

dmitriid12:05:08

This entire ordeal is surprisingly difficult 😞

dmitriid12:05:09

Thank you all!

cmal11:05:16

Hi! Is there a demo project that uses Node.js+express.js + reagent(cljs)? I want to use express.js to do route dispatch and do not use clojurescript when the route satisfied some rules. For example, only when app.use('/app') should rendered by clojurescript/reagent. I don't know how. Can anyone help me? Thanks!

benbot18:05:38

I think this is something cljs should keep an eye on https://prepack.io/

juhoteperi18:05:21

@benbot Cljs already uses Closure Compiler

benbot18:05:57

I know, thats why I think this is an important thing to keep an eye on. If prepack ever gets to a point that it’s better than the Closure compiler… a switch might not be bad

benbot18:05:27

Like long long term obv… but it’s still something to keep a watch on imo

dominicm18:05:50

@benbot the goog closure api is relied on a lot by cljs projects. That goes away with a switch n

benbot18:05:24

yeah it’d be a situation like python 2 and python 3… but if the benefits are there

dominicm18:05:13

Google have a keen interest in having this technology in their compiler, I wouldn't be surprised if that happened

dnolen18:05:51

@benbot definitely interesting, but probably a couple of years development required for us to consider

dominicm18:05:44

I wonder if it would work on minified code? Could be used as an extra by users?

souenzzo18:05:19

Keep eyes on "when someone implement some features in closure compiler"?

benbot18:05:23

Keep eyes on “when a large company like facebook makes something like a closure compiler”

benbot18:05:31

prepack is a facebook project

zacanger18:05:26

probably yes to working on minified code, since babylon should be able to. and also probably yes, as a step in the build chain. seb markbage says there are still issues with Map and Set, though, so probably not yet.

benbot18:05:38

@dnolen for sure, I’m just bringing it to light… just in case

souenzzo18:05:28

Being facebook earn my respect Initial site looks like "just one more awesome javascript framework that will be the best of besters"

benbot18:05:48

yeah there’s no facebook branding on the site, but the github repo is under facebook’s account

souenzzo18:05:23

closure compiler also manage modules and clojurescript use it to manage ns's...

souenzzo18:05:42

prepack do something like?

claudiu19:05:16

doesn’t google compiler do optimisations like prepack ?

darwin19:05:25

@claudiu no, at least not stuff “How does it work?” on prepack website

dnolen20:05:43

Google Closure does do many runtime optimizations

dnolen20:05:56

but seems much more concerned about code size than Prepack at least at this point

rgdelato20:05:46

> "Prepack focuses on runtime performance, while the Closure Compiler emphasizes JavaScript code size."

danielcompton20:05:27

Where does the JS JIT fit into all of this? My naive assumption is that a lot of what prepack does (currently) is what the JS engines would also do on any hot code paths?

spinningtopsofdoom21:05:24

My intuition is that prepack pre evaluates the JS code making it easier and faster for the JS JIT to analyze running code. Essentially trimming the work the JIT needs to do

Roman Liutikov21:05:10

@danielcompton I've done some profiling and it seems like Prepack code inlines lots of stuff https://twitter.com/roman01la/status/859859125890633728

Joe R. Smith22:05:59

an exported function appears to lose its constructor.name w/ advanced compilation. I need it for JS interop– does anyone know if this is expected behavior?

anmonteiro22:05:44

@solussd I think you could only solve that with a Closure @nocollapse annotation

anmonteiro22:05:03

I think you can make it work with :jsdoc metadata

anmonteiro22:05:48

(defn ^{:jsdoc ["@nocollapse"]} foo
  ...)

anmonteiro22:05:19

@solussd if it’s an object constructor, you may also want to add the "@constructor" annotation

anmonteiro22:05:34

let me know if that solves your problem

Joe R. Smith22:05:37

@anmonteiro just tried it– still getting an empty string for <instance>.constructor.name

Joe R. Smith22:05:18

I used both annotations you suggested

anmonteiro22:05:48

@solussd can you share a snippet?

Joe R. Smith22:05:33

sure, let me reproduce w/ a simpler example. Right now it’s a macro

anmonteiro22:05:52

sure it’s not a macro bug? 🙂

Joe R. Smith22:05:18

yeah– the expansion looks correct. 🙂

anmonteiro22:05:39

you’d have to do something like ~(with-meta sym {:jsdoc ["@nocollapse" "@constructor"]})

anmonteiro22:05:45

I’m sure you did it

Joe R. Smith22:05:04

here, I’ll send the macro (direct message snippet)