Fork me on GitHub
#clojurescript
<
2018-03-26
>
lwhorton04:03:59

am I going crazy? i thought you could have a my-ns.core that’s my_ns/core.clj as well as a my_ns/core.cljs and it’s totally fine? for example, if I wanted to do this:

(ns my-other-ns.core
  (:require [my-ns.core :refer-macros [some-macro]]))
this is all fair because a cljs compiler knows that the .cljs file doesn’t have macros, so it must the .clj file I’m referencing?

thheller09:03:03

It is totally fine but the my-ns.core CLJS file must have a (:require-macros [my-ns.core]) for the :refer to work.

thheller09:03:41

so the CLJS ns must require "itself" for others to be able to refer to macros directly

lwhorton13:03:12

i ended up figuring out the issue was that one of my macros refered to my-ns.core/some-js-fn and I was unintentionally using (:require [my-ns.core :as some-js-ns]) which isn’t allowed

blackawa04:03:25

My understanding is we cannot require .clj from cljs file. So your code may not find proper macro…

levitanong06:03:36

@lwhorton try doing (:require-macros [my-ns.core :refer [some-macro]])

leongrapenthin10:03:03

How do I do npm deps with cljs10?

leongrapenthin10:03:31

I want to simply try out loading react and react-dom per npm-deps

leongrapenthin10:03:56

It did work with the previous cljs 1.9 release

leongrapenthin10:03:12

Now it appears that the process shim is broken somehow

leongrapenthin10:03:39

The compiler emits production code for react-dom. That invokes react-doms mysterious checkDCE function that breaks everything.

leongrapenthin10:03:14

I had to set :process-shim explicitly to true (doc says its set true by default but at least with -r it isn't)

leongrapenthin10:03:47

But even though in runtime process.env.NODE_ENV is "development", the compiler has emitted the production stuff and react-dom won't load

leongrapenthin10:03:33

I have disabled aot-cache

leongrapenthin10:03:46

Or are there new requirements

leongrapenthin10:03:00

how to use npm deps ?

dnolen12:03:46

@leongrapenthin it sounds like you’re talking about an issue specific to React

dnolen12:03:59

many libs are not going to consider that env var and this isn’t really a problem

dnolen12:03:07

but I can’t offer any more real information, I tested with a bunch of other libs, but not React recently

leongrapenthin12:03:37

@dnolen Well it worked with the last stable 1.9. Also my brief debugging session indicated that :process-shim simply doesn't work as it did before anymore. It is not enabled by default, and it appears to set NODE_ENV to "production" during code emission and to "development" only later. So should I file a ticket or repro this?

dnolen12:03:01

a ticket with precise information is best

leongrapenthin12:03:05

react-dom/index.js has this line "if (process.env.NODE_ENV === 'production') {"

dnolen12:03:20

for anything Node module process related unless you know exactly what is wrong

dnolen12:03:34

it’s not worth describing

leongrapenthin12:03:34

it is eliminated and the code for the true case is emitted

dnolen12:03:00

but even better, if you can discover what’s wrong, just supply a patch

leongrapenthin12:03:14

:)) will look into it later today

dnolen12:03:03

@leongrapenthin process shim stuff is all in cljs.closure, but if you what you says is true you should also just try to set the :closure-defines yourself

dnolen12:03:37

the process shim ns exists so that this can be done

dnolen12:03:52

along with preventing React from breaking as it expects it

dnolen12:03:29

ClojureScript 1.10.238 is released https://clojurescript.org/news/2018-03-26-release

👍 24
🎉 56
cljs 8
benzap12:03:47

That clojurescript commandline is pretty slick, good stuff!

achikin12:03:56

Does anyone use material-ui-next?

achikin12:03:28

I have a strange issue. Cursor jumps to the end of the atom-powered textfield each time I edit it.

mikerod14:03:31

This is a fairly common issue that pops up in managed components. The reagent channel would probably have more input, but one link has already been provided here I see.

achikin12:03:56

And it only happens on mui text field

benzap12:03:54

@achikin I had similar issues, you could try using :default-value instead of :value

benzap12:03:34

oh nvm, I don't think that solves your issue

benzap12:03:56

yeah, I figured 😕

achikin12:03:43

@benzap it kind of solves the issue, but now there is some issue with reactive deref

achikin12:03:08

Those inputs use the same atom but mui one does not react to atom changes any more

benzap12:03:23

think it's because :defaultValue just sets the init-state within the input element, and then leaves it unmanaged

benzap12:03:08

I couldn't figure out why the mui input field acted like that either, i'm using it within rum. I'm guessing you're using reagent?

achikin12:03:30

Yes, its reagent.

achikin12:03:49

Do you have the same issue with rum?

benzap12:03:59

yeah, I believe it's similar

benzap12:03:01

I'm curious about how you're wrapping the TextField to work in your code?

benzap12:03:12

Is that some sort of adaptive thing that reagent does?

benzap12:03:33

I ended writing my own adapter code for all of my material-ui stuff

achikin12:03:37

adapt-react-class

achikin12:03:23

It's a usual way to wrap React component to work with Reagent

juhoteperi12:03:00

@achikin Check https://github.com/madvas/cljs-react-material-ui/issues/17 it shows some workarounds (best workaround would require Reagent change)

dum3ng13:03:34

Tried to use npm library by :npm-deps. I add :npm-deps {"react" "16.2.0" "react-dom" "16.2.0" "create-react-class" "15.6.3" } to cljsbuild compiler option. But there is this code

if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
checkDCE();
module.exports = require('./cjs/react-dom.production.min.js');
} else {
module.exports = require('./cjs/react-dom.development.js');
}
in index.js file of react-dom package, while the compiled version just eliminates the if and treat NODE_ENV to true, the result is always throw an error.

dum3ng13:03:52

The value of process.env.NODE_ENV is "development". Does not know why closure compiled version treat the if clause as true?

dum3ng13:03:03

Does it need some additional config to make the npm-deps work?

dnolen13:03:43

but still not enough information

dnolen13:03:00

we only set “production” if optimization is not :none

dnolen13:03:11

see cljs.closure/add-implicit-options

leongrapenthin13:03:47

yeah, setting :closure-defines {"NODE_ENV" "development"} doesn't do it unfortunately

dum3ng13:03:48

{:npm-deps {:react "16.2.0"
                                      :react-dom "16.2.0"
                                      :create-react-class "15.6.3"}
                           :externs ["process.js"]
                           :main "hello-npm.core"
                           :output-to "resources/public/main.js"
                           :output-dir "resources/public/js/out"
                           :asset-path "js/out"
                           :optimizations :none}}

dnolen13:03:17

@leongrapenthin that isn’t how :closure-defines works

dnolen13:03:37

fully qualified

dnolen13:03:55

like I said go look at cljs.closure/add-implicit-options and see for yourself

dnolen13:03:03

and fix this for yourself if somehow it is wrong 🙂

juhoteperi13:03:01

I'm running Cljs 1.10.238 + Reagent 0.8-alpha2 with Node modules and it is working for me.

leongrapenthin13:03:13

it doesn't work with explicitly setting :closure-defines {"process.env/NODE_ENV" "development"} either

leongrapenthin13:03:47

very strange that the compiler emits the production clause

juhoteperi13:03:23

Oh right, the error is from Chrome React Developer Tools

juhoteperi13:03:38

I don't usually have that enabled so haven't seen this error

juhoteperi13:03:34

If you check process.env.NODE_ENV on browser, it is correctly set to development

juhoteperi13:03:47

It is just that the React 16 CommonJS bundle is completely insane

leongrapenthin13:03:45

@juhoteperi can confirm that disabling dev tools does the trick

juhoteperi13:03:54

React 15 would also work

leongrapenthin13:03:08

nonetheless if you compare react-dom/index.js from the node_modules folder with the node_modules folder in the compiler output it makes no sense

leongrapenthin13:03:15

the call to checkDCE should never be emitted

juhoteperi13:03:18

This problem is not related to process.env at all

leongrapenthin13:03:41

is it only since 1.10 because closure compiler has been updated?

leongrapenthin13:03:53

@juhoteperi Thanks for all the clarification.

leongrapenthin13:03:07

and also @dnolen for helping invalidate my theory quickly 🙂

Alex Miller (Clojure team)14:03:10

however, that error sounds like it might be related to security. I’m curious what version of Java you have installed (`java -version`)

👍 4
dnolen14:03:34

@alexmiller we followed up in #beginners

dnolen14:03:44

it was Java 9, but I’ve never seen that

dnolen14:03:56

I’m running Java 9 by default

Alex Miller (Clojure team)14:03:48

I have seen people report this, but I don’t remember why

Alex Miller (Clojure team)14:03:34

things to check: use -Sforce to ensure you don’t have any classpath cached, see if this works if you go via leiningen dep, check whether you have anything funky in your Maven ~/.m2/settings.xml

ikr14:03:17

@alexmiller Weird. After reinstalling 9 -> 8 -> 9, it works with jdk 9 too now. And I did wiped .m2, and the local .cpcache and ./out

Alex Miller (Clojure team)14:03:47

hard to tell which one of those was important :)

ikr14:03:41

Well, enough to move on for me now. @alexmiller thanks!

michaels16:03:41

going through the new clojurescript guide. 😍

pmooser17:03:08

Looks like there's a lot of new information (or maybe I'd just missed it before) about using npm dependencies and stuff.

dnolen17:03:34

No new information really, we need to do some updates in fact

michaels17:03:27

Finished the quick start guide.

michaels17:03:42

Super easy to get up and running. Much faster than the old days, no hiccups.

michaels17:03:51

And TTFX went from 0 to ?. 😄

dnolen17:03:21

Thanks for the feedback!

oVerde18:03:03

Hello guys, is there an alternative for Redux Offline on Cljs? Or just a good guide to PWAs?

achikin18:03:46

You could try re-frame and follow their guide.

oVerde19:03:39

Oh! I should had paid more attention to the guide then

oVerde19:03:39

Oh! I should had paid more attention to the guide then

oVerde19:03:15

No luck, didn’t found it

oVerde19:03:33

This has some codes to leverage the cache issues

worlds-endless19:03:34

Anyone know of any good shopping sites (perhaps with code available) written in Clojure?

Drew Verlee20:03:54

With respect to everyone involved. Is their a difference between lumo and clj for the purposes of creating a executable node js file. Both aim to produce a js executable, right?

borkdude20:03:12

@drewverlee Most notable difference is that lumo uses self hosted clojurescript and lets you execute scripts without setting up a project. So it’s very suited for one off scripts.

borkdude20:03:36

Of course clj with cljs.main lets you do the same now, but the startup time is longer

borkdude20:03:39

and you require a JVM, which is not all that bad though, but for a little script it can be too much

richiardiandrea20:03:24

@drewverlee another thing to add for js transpilation is that the Closure compiler port to JS is not completely the mirror of the JVM one. YMMV

quang20:03:58

Question: Is there anything like babel/coffee-script translator for CLJS? like: https://babeljs.io/repl/

mfikes20:03:42

I guess the question is "What are you trying to achieve?"

quang21:03:29

sweet thanks @borkdude exactly what I was looking for.

quang21:03:25

just trying to get use to JS interop syntax

mfikes21:03:24

Cool. Another alternative is to use Lumo or Planck with -v, which will cause them to print out the JavaScript for any form you enter. Or use any REPL in :repl-verbose mode http://blog.fikesfarm.com/posts/2015-06-15-see-js-in-cljs-repl.html

quang21:03:13

Thanks @mfikes I'll check those out.

quang21:03:47

hey is (.format(js/moment)) no space after .format, proper? or is that considered bad style?

mfikes21:03:17

Another example showing how trivial it now is to put a REPL in verbose mode is at the very bottom of https://clojurescript.org/news/2018-03-26-clojurescript-command-line

mfikes21:03:09

(.format(js/moment)) would normally be written as (.format (js/moment))

mfikes21:03:05

The first form seems to kind-of imply that you are calling format with an argument of js/moment

mfikes21:03:28

But really it is evaluating a call (js/moment) and then passing that as the first argument to .format

mfikes21:03:42

Likewise, you'd put a space in (str(js/Date.)) and instead write (str (js/Date.))

quang21:03:55

I'm surprised (js/moment"2018") doesn't throw an error...

quang21:03:24

tempted to save the extra space... but something is telling me that's a bad idea...

mfikes21:03:08

Hah. You will make a lot of developers pause and wonder about code like that 🙂

quang21:03:37

I'm liking the terseness of Clojure... why wouldn't that be a good idea?

mfikes21:03:41

By the way, since you are looking into JavaScript interop, there is a draft guide that hasn't yet been published, might be useful https://github.com/mobileink/clojurescript-site/blob/88805681e76a86dcab068ec8b574ed733ebd5f8c/content/reference/javascript-interop-ref.adoc

mfikes21:03:17

(js/moment"2018") is a bad idea because, even though I work on the ClojureScript compiler, to be honest, I would have to try such an expression to see if it is even handled properly 🙂

quang21:03:25

nice @mfikes Thanks for that link!

mfikes21:03:56

I mean, I guess we should all immediately know if (js/moment"2018") is well formed, but, life is short 🙂

dnolen21:03:19

We need an interop reference page on the site

quang21:03:29

> I would have to try such an expression to see if it is even handled properly hmm :thinking_face: yeah I'm surprised it compiles... but I guess that might change in the future? it seems like it should throw an error

mfikes21:03:49

Yean @dnolen I think we just need to wrap up the draft. It is too useful to not have 🙂

mfikes21:03:45

Well, the semantics of (js/moment"2018") are probably well defined, but I suspect if you try to elide spaces around lots of code, you might find things that don't work as expected. For example, I think this used to work in very old versions of Clojure: (#(str%1) 1)

borkdude21:03:27

if moment("2018") is correct from the console, then (js/moment "2018") would be valid. what’s wrong with it, despite the deprecation warning you’ll get from this library?

mfikes21:03:46

If I had to guess, @quang is curious about eliding unnecessary spaces from code.

dnolen21:03:15

That wip page is a bit too much and cover stuff we don’t want to cover, we just need a minimal page with the basics

borkdude21:03:50

I used to go to http://himera.heroku.com/ for a cheatsheet on js interop, but it’s down

mfikes21:03:51

That would match the conciseness David mentioned. We should get the Heroku examples, which were to-the-point and useful.

borkdude21:03:31

you can still run this locally: https://github.com/fogus/himera

john21:03:47

hsts 😞

mfikes21:03:03

Another thing that I don't think is documented is the Math pseudo-namespace.

quang21:03:06

fyi I guess (js/moment2018) would definitely not work as wanted (passing a number), so I guess it's better to always add that space...

mfikes21:03:18

IMHO, whitespace formatting in Clojure has never really been an issue. It is mostly about where to choose to put forms on new lines that are getting a little long.

👍 12
mfikes21:03:11

In other words, it truly does become difficult to discern who wrote a bit of code because it is so uniform.

dominicm21:03:13

I have a contrasting experience, I can detect several other members of my team from the code.

mfikes21:03:40

(You know, you've worked on projects in other languages where you can just tell by the style, who on the team wrote that code 🙂 )

borkdude21:03:46

I can still recognize who of my colleagues wrote what usually 😉

mfikes21:03:09

I can only tell Nathan Marz's code. Otherwise it all looks the same to me. 🙂

bronsa21:03:05

ztellman also is quite easy to spot by the ns form

mfikes21:03:54

Ahh, I haven't had the pleasure of reading much of his code. I should do that more frequently.

dominicm21:03:19

@U060FKQPN other than the attribution, what's unique about his ns form?

dominicm21:03:41

Oh, import is flat. Very flat. The rest looks normal.

dominicm21:03:53

This seems reasonable

dominicm21:03:06

Now to go figure out marz's novelty

bronsa21:03:21

well, he's also one of the few people to actually use the nested ns syntax

bronsa21:03:31

(`[foo [bar [baz ..`)

dominicm21:03:12

@U060FKQPN I see that anytime people use refactor on the default settings. I'm quite used to that, even though I suggest they turn it off.

dominicm21:03:40

@mfikes the novelty isn't obvious to me, have you got a clue?

bronsa21:03:05

closing ) in new lines is what I remember from nathan's code

dominicm21:03:25

I did see a few of those in specter. Some on my team do this too.

dominicm21:03:40

Most of his code seems free of them now though.

mfikes22:03:02

Yeah, that's what I was referring to. Perhaps Nathan's style has changed, but the closing parens on their own lines was very unconventional looking.

quang21:03:30

Elm has a nice philosophy on that, they use whatever whitespace that's causes less diff's

quang21:03:41

> Goal: a consistent style that is easy to read and produces clean diffs. http://elm-lang.org/docs/style-guide

borkdude21:03:48

Well, sometimes I think: who wrote that.. and magit-blame tells me I did… 😛

👍 8
quang21:03:48

(not= (f'x) (f 'x)) as well... space it is...

zentrope22:03:30

Golang is super fun with diffs on Github. All those super wide 8-space “tab only” indentations.

zentrope22:03:18

I think you can fix it a bit with ?ts=2 on the URLs for github, but there’s no way I know of to make that persistent.

😮 4
michaels22:03:58

I can identify one coworker by 3 or 5-space tabs. 😬

😬 8
caleb.macdonaldblack22:03:22

I’m using doo and phantomjs for my cljs unit tests and my test diffs are really hard to read. Are there any tools that can pretty print the result and maybe even highlight the what’s different?

nenadalm19:03:20

If you're using karma, you can try to upgrade to newer version of karma-reporter (https://github.com/honzabrecka/karma-reporter). Doo has dependency on some older version.

caleb.macdonaldblack22:03:36

I managed to get pjstadig.humane-test-output to work for pretty print

caleb.macdonaldblack22:03:07

It does the diff too

cfleming23:03:49

I’m using promesa with some Node code on AWS, and I’m suddenly getting “Should be only used in alet macro.” errors, which should be catching uses of await outside of alet. But all mine are within alets - does anyone have any idea why that might happen?

justinlee23:03:07

@cfleming I know that go blocks can’t traverse function boundaries and the promesa docs say it is using go machinery, so I wonder if that’s your problem?

cfleming23:03:17

@lee.justin.m Interesting, I hadn’t considered that. But there’s nothing in the doc or the docstring to suggest that sort of restriction around its use.

justinlee23:03:59

I would be shocked, shocked I say, to learn the a clojurescript library docstring was anything less than comprehensive. 🙂

cfleming23:03:25

However this did previously work for me, so something odd has changed. Perhaps a clean build is in order.

cfleming23:03:46

(not this exact code, but using alet in the way I’m using it now).

justinlee23:03:47

and i could be wrong. although i’ve looked at the promesa library many times, i haven’t yet tried it

cfleming23:03:58

When it works, it’s really lovely.

justinlee23:03:58

There has to be a better way than what core.async is doing right now, so maybe I’ll try it.

cfleming23:03:04

Also, to be fair to the funcool guys, their doc is usually excellent.

cfleming23:03:34

Yeah, I like it better than core.async, especially for code which is really emulating synchronous calls (like AWS)

cfleming23:03:45

Right. The problem is I don’t know how much of the core.async stuff is being used - an alet is always contained within a single function, but I don’t know if there are restrictions on functions which call it.

justinlee23:03:00

it seems like it would be very hard to do. even in javascript, async/await can’t cross function boundaries. you have to redeclare an async function and await it