Fork me on GitHub
#clojurescript
<
2017-08-03
>
noisesmith00:08:04

when using :exclusions it can also be a good idea to explicitly add a dep for the version of the thing you want at the top level, before anything that depends on it

dealy00:08:35

yea, that's how I fixed it, had to add guava 19 at the top

dealy00:08:25

its weird tho, I hadn't made any dependency changes in the past 2 weeks then all the sudden today it stopped working, really confusing

mrchance00:08:47

Behold the classpath 🎉

dealy00:08:25

@mrchance I can't tell if that emoji i sa piece of pizza or a kazoo, or what

mrchance00:08:48

Little bit of both, I guess ^^

dealy00:08:04

it made me smile

mrchance00:08:15

Then it already served its purpose 🙂

mrchance00:08:21

Now, if someone can tell me how syntax quote works when expanding clojurescript macros, my day is made 🙂

mrchance00:08:30

What does (foo ...) expand to when I use the same ns trick for macro and the matching cljs namespace has a foo function?

mrchance00:08:58

Can I rely on it being the foo from that ns, or should I always fully specify the ns in the macro?

mrchance00:08:12

sorry, I meant

`(foo ...)

mrchance00:08:34

Also, it didn't seem to work for a record in that namespace :thinking_face:

mrchance00:08:52

In Clojure that's not an issue, because the macro usually lives and is evaluated in the same ns that houses the functions it references...

lumpy00:08:03

has anyone ever had an issue that appears only when code is optimized? I’m running into a weird issue with https://github.com/benhowell/reagent-quill that only happens when the code is optimized.

noisesmith00:08:22

@mrchance think of how many clojure.core functions you use though - ` namespace qualifies things such that your code works even if the code using the macro has renamed or hidden parts of the other ns

jeaye00:08:50

@lumpy Typically things having to do with code using (.foo x) and (.-foo x).

mrchance00:08:52

@noisesmith yes, I understand why that is needed in general, I just want to know how it works in cljs. Not sure how your reply answers that, maybe I'm being daft 🙂

jeaye00:08:04

@lumpy Are you using either?

mrchance00:08:35

So you're basically saying I should fully qualify all symbols?

mrchance00:08:49

That's a bit... unwieldy

noisesmith00:08:03

` qualifies the symbols, you shouldn't have to do it by hand

noisesmith00:08:17

just be sure the cljs is requiring the right namespaces somewhere at runtime

mrchance00:08:30

Hm, so I had a foo.cljs and a foo.clj file, the cljs file required the clj one and referred the macro, which had a reference to a record in foo.cljs in it. This didn't work. For the functions in foo.cljs however, it did. That's what confused me

mrchance00:08:29

Something like

(defmacro pipe [x]
 `(Pipe. ~x))

mrchance00:08:45

(Little more complicated, I know this doesn't warrant a macro :)

mrchance00:08:11

Figwheel handled it pretty weirdly too, I got a very short popup that looked like an undefined var warning, which immediately disappeared and was replaced with the success badge Oo

lumpy00:08:27

@jeaye yes that seems to be the problem

lumpy00:08:43

is there a good way to fix those issues

jeaye00:08:46

@lumpy Ok, use cljs-oops for all member access. It's a superb library.

lumpy00:08:18

awesome, I’m so mad I didn’t ask here sooner

lumpy00:08:16

is there a known reason this happens?

mrchance00:08:41

@noisesmith I still don't understand how that works, if a macro does

`(foo x#)
how does it know what foo it should expand into? In Clojure, it's always the foo in the same scope as the macro, but in cljs those are different phases, I usually even can't require the file with the right foo because it will be a cljs file

noisesmith00:08:22

it's the defining namespace that determines the expansion

mrchance00:08:55

ok, so it checks in the cljs namespace that matches its own, always?

noisesmith00:08:55

oh, - good point, that means that auto-expanding to the right cljs namespace would be tricky in some cases

noisesmith00:08:37

it's a decent reason to have stub clj namespaces with the same path as the cljs namespace you want to emit calls to

mrchance00:08:36

ah, that's not a problem, I usually have both anyway, since I like to be able to omit :require-macros and treat them transparently

mrchance00:08:09

But in theory it should work similarly for records, correct? Nothing different there?

noisesmith00:08:04

sure - you can refer to records via the ns level vars that get created rather than the raw classes / methods sometimes as well

noisesmith00:08:31

(that might make things simpler)

mrchance00:08:37

(ns foo.awesome)

(defmacro to-bar [x]
 `(Bar. x))
will always expand to (foo.awesome/Bar. x) ?

mrchance00:08:42

Ah, good point

mrchance00:08:54

Yeah, I might just use the helper fns

noisesmith00:08:39

and the answer is yes, unless Bar is in scope referenced from some other ns

mrchance00:08:11

I should still qualify calls to other libraries though, and hope they have been required somewhere? e.g. cljs.core.async/chan or something like that?

noisesmith00:08:20

that seems reasonable

mrchance00:08:35

ok, I think I got it, thanks again!

jeaye00:08:16

@lumpy Names are mangled during :advanced optimizations, to be shorter.

jeaye00:08:06

Of course, cljs-oops supercedes aget and is much more preferable.

lumpy02:08:51

Thanks @jeaye this was a lifesaver

jfntn02:08:09

Is there something like criterium for cljs?

ag03:08:24

js/console.time ?

mfikes03:08:17

@jfntn See cljs.core/simple-benchmark

mfikes03:08:50

Or, even simpler, cljs.core/time

jfntn04:08:33

@mfikes simple-benchmark is what I’m using, but I can’t explain why I’m seeing a lot more variability accross runs than with the same code on the jvm

mfikes04:08:44

@jfntn I've seen JavaScriptCore's FTL optimizer create mysterious variations https://github.com/mfikes/planck/issues/417

jfntn04:08:28

yeah seeing similar things with node, though it’s not quite as dramatic

urbank10:08:27

I'm trying to make a cljsjs package for react-dom/test-utils

urbank10:08:00

Does anyone know where the repo is ?

urbank10:08:04

@U61HA86AG Hm, right. Should be it I suppose.

sundarj10:08:29

yeah React is a monorepo

juhoteperi11:08:46

I think the hard part this this is that there is no browserified JS ready for this file

urbank12:08:36

@juhoteperi Yeah, couldn't find one. So I guess it should be browserified and added to the cljsjs repo?

juhoteperi12:08:13

If it is possible to browserify it, yes

juhoteperi12:08:36

It would make sense to package this to cljsjs/react-dom, similar to how it is included in same npm package, but not sure if I want to have browserify included in main React packaging script

juhoteperi11:08:00

I packaged React 16 beta 2 to Cljsjs: https://github.com/cljsjs/packages/commit/c49c89169b9bb7391508c5f5e19d35514feee283, seems to break some tests at Reagent at least

jfntn13:08:06

What would be the fastest implementation of a global key-value cache? Current status: (def cache (volatile! (transient {})))

jfntn13:08:17

Thought volatile! would be slightly faster due to lack of validators, watches etc?

curlyfry14:08:47

volatile! does not have any atomicity guarantees though, so it's not thread safe. I believe it's intended for smaller scope changes in a single thread (like in stateful transducers).

thheller14:08:49

there are no threads in JS so volatile! is fine (and slightly faster)

oskarth15:08:44

@dnolen fwiw the issue from yesterday was a REPL environment one, a bug in a version of bignumber (which web3 relied on) hangs in Safari / similar envs (React Native on iOS) but not in a Node REPL, fixed by depending on a separate version of bignumber and doing arithmetic there

dnolen15:08:21

@oskarth ok good to know 🙂

fabrao18:08:50

Hello all, a silly question -> how to create <ul uk-accordion> from [:ul {?}]?

anmonteiro18:08:41

@fabrao {:uk-accordion true}?

fabrao18:08:28

well, I did this but didn´t work, that because I asked here. Is that the correct way?

lvh18:08:41

Hi. I’m following https://clojurescript.org/guides/javascript-modules and trying to load a vendored JavaScript project with CommonJS modules. Requiring the namespace fails (“No such namespace”). Re: this sentence: > Notice that a :foreign-libs entry may now specify a directory for :file. In this case, the ClojureScript compiler will recursively search this directory for .js files and automatically create the :foreign-libs entries for you with the supplied options. Is there a way to get the cljs compiler to list the foreign-libs entries it has created to aid in debugging? Currently I have the following foreign-libs entry: :foreign-libs [{:file "vendor" :module-type :commonjs}]; where “vendor” contains one directory, csp-report-norm, the contents of which are a local copy of this git repo: https://github.com/tollmanz/csp-report-norm

lvh18:08:18

:verbose true is already on so that’s not it 🙂

fabrao18:08:21

It seems that I can only use {:data-stuff "something"}

dnolen18:08:31

@lvh currently there is no way to do debug, though that’s a probably a good feature to add to :verbose

dnolen18:08:06

@lvh no one might have the time to look at this right now, so best thing to do is make a minimal case - zero tooling except Quick Start uberjar

dnolen18:08:13

if you can repro then make a ticket

dnolen18:08:18

do not link outside the ticket

dnolen18:08:24

add all steps to repro to the ticket

lvh18:08:41

(also hi @dnolen thanks for all the work you’ve been doing; I know it’s a team effort but so much cool stuff since I last touched CLJS :))

lvh18:08:52

okiedokie, I will try to reproduce

dnolen18:08:10

if you like add separate issue about dumping foreign libs, probably something we could add to cljs.build.api

anmonteiro18:08:31

I’ll look into it right now

dnolen18:08:48

@lvh we’ve been a lot better about adding test cases for all these different combos - so if there’s an issue we’ll try to make sure it doesn’t regress

anmonteiro18:08:25

I know what’s wrong

anmonteiro18:08:34

@lvh there’s no :provides entry in your foreign-libs definition

anmonteiro18:08:13

hrm, that might not be needed

lvh18:08:27

Ah. From that instructions page I liked, just after the part I quoted: > The :provides namespace for each entry will be automatically computed from the directory structure. … so I was also expecting that to work for my vendored repo.

anmonteiro18:08:35

so how are you requiring it?

anmonteiro18:08:21

(require [vendor.index]) should be how you require it

anmonteiro18:08:46

csp-report-norm.index

fabrao18:08:32

[:ul {:data-uk-accordion true}] -> <ul data-reactroot="" data-uk-accordion="true" class="uk-accordion"></ul> WTF !!!?

lvh18:08:40

Ah; I was requiring it as [csp-reports-norm]; not with index, I thought that was implicit. That made the compiler happy, but it still doesn’t appear to be copied into out/; notably, when I try to run it with node, I get:

cspshovel/out/goog/base.js:1357
              throw Error('Undefined nameToPath for ' + requireName);
              ^

Error: Undefined nameToPath for vendor.csp_reports_norm.index
... (stacktrace omitted for brevity)
… which is what I think that means

anmonteiro18:08:42

the only problem I’m seeing is that the package has a validator dependency

anmonteiro18:08:47

which you’re not honoring

lvh18:08:00

I’ll try and create a minimal reproducer. Thanks @anmonteiro 🙂

anmonteiro18:08:39

@lvh is this with :target :nodejs?

anmonteiro18:08:58

that might be your problem

anmonteiro18:08:55

here’s the problem: we stopped converting modules entirely when target is nodejs cc @dnolen

anmonteiro18:08:07

but this is not a good assumption, and we should only do that for node modules

dnolen18:08:17

yeah just came to the same conclusion here

anmonteiro18:08:40

I can put together a patch today

anmonteiro18:08:46

should be an easy fix

lvh18:08:23

welp, I’m glad my problem was interesting at least — does that mean you no longer need an issue from me @anmonteiro ?

anmonteiro18:08:32

no, I can create one

anmonteiro19:08:27

I’ll make sure to include a test so we don’t regress 🙂

lvh19:08:00

cool; thanks 🙂 If I understand what you’re saying correctly, this wouldn’t be a problem if the dep was added in package.json instead of being vendored?

anmonteiro19:08:34

if you use npm-deps you’ll be able to require it

anmonteiro19:08:47

@lvh also simply because we don’t even attempt to run those through Closure if your target is Node

anmonteiro19:08:05

there’s a native require, we use that

lvh19:08:08

I didn’t know about :npm-deps — is that equivalent to a package.json with the appropriate devRequirements for cljs and the dependency?

lvh19:08:13

(if so that’s really convenient)

anmonteiro19:08:41

let me know if you have further questions after reading that

whou19:08:41

is there a ssl https client library ?

whou19:08:49

for clojurescript ?

nooga19:08:32

how do I forbid the compiler from mangling things like window.speechSynthesis ?

fabrao19:08:01

@whou I think you can use ajax-request directly to https

whou20:08:04

@fabrao i am writing a clojurescript + planck script to ping a server that requires two way ssl, without the help from the browser, i think i will need to establish the trust somehow myself. Do you happen to know an example how to do this on clojurescript? or am i misunderstanding something here ?

whou20:08:46

something like http-client + openssl package in chicken scheme, but i really want to stay clojurescript

thheller20:08:26

@whou pink @mfikes whether planck has a https client, otherwise you might want to try lumo since that is node which has https support

mfikes20:08:52

Yes, Planck has https support. You can, for example (planck.http/get "") It is based on libcurl

pawel.kapala20:08:57

I’ve been using :npm-deps for two days now, and I’ve already encountered two google closure compiler bugs. Do you have any work-around technique for those bugs, or do I have to wait for upstream fix? I’ve been trying to fork and patch affecting npm modules, but that’s dubious… (FYI: I’m referring to https://github.com/google/closure-compiler/issues/2377 and https://github.com/google/closure-compiler/issues/2450)

juhoteperi20:08:15

@pawel.kapala 2560 has been fixed in master

pawel.kapala20:08:54

@juhoteperi Thanks, I’ll have a look at the list. Regarding 2560, if it’s fixed in master. Silly question: how can I use it in lein project. Special dependency? SNAPSHOT?

juhoteperi20:08:28

run mvn -DskipTests at Closure-compiler dir and replace closure dependency with version 1.0-SNAPSHOT

josh_tackett20:08:41

Anyone know the best library to draw on files?

thheller20:08:03

@juhoteperi the @atlaskit/* packages are fun too, eg @atlaskit/navigation references a whole bunch of packages with fun wrappers

thheller20:08:49

all webpack’d packages with externals

juhoteperi20:08:06

@thheller https://unpkg.com/@atlaskit/[email protected]/dist/bundle-cjs.js ? Closure has a test case for one webpack UMD wrapper, so mayber this works?

thheller20:08:33

--- node_modules/@atlaskit/avatar/dist/bundle.js:2
The define function must be called as a top-level statement.
--- node_modules/@atlaskit/blanket/dist/bundle.js:2
The define function must be called as a top-level statement.
--- node_modules/@atlaskit/field-base/dist/bundle.js:2
The define function must be called as a top-level statement.

thheller20:08:38

I got a bunch of not working things

anmonteiro20:08:48

@juhoteperi @pawel.kapala FWIW the Closure Compiler team started publishing nightlies a while ago

anmonteiro20:08:02

so you can just add 1.0-SNAPSHOT and it’ll download the nightly snapshot from Maven

anmonteiro20:08:05

no need to build it yourself

juhoteperi21:08:38

@thheller dist/bundle.js looks like the browserified file, package.json webpack property points to dist/bundle-cljs.js

anmonteiro21:08:34

^ the errors above are because you’re setting AMD -> CJS conversion to true

anmonteiro21:08:12

disabling that will either 1. produce a better error, 2. convert the file successfully (no guarantees about working at runtime)

thheller21:08:29

wait now there is a webpack property as well?

thheller21:08:21

didn’t notice that

juhoteperi21:08:53

I think JS build tools just add those properties when ever they feel like it

juhoteperi21:08:14

"main": "dist/bundle.js",
"webpack": "dist/bundle-cjs.js",
"jsnext:experimental:main": "dist/es/index.js",
"ak:webpack:raw": "src/index.jsx",
"types": "src/index.d.ts",

thheller21:08:21

hehe yeah it has a bunch of them

chrisbroome21:08:40

there's also a module property you can add that will have webpack automatically pull in the ES6 version of a dependency if its defined

juhoteperi21:08:05

@anmonteiro's patch adds option to Closure to configure this, so it will be possible to set it to ["webpack", "browser", "main"] or something in future

chrisbroome21:08:06

which is better for tree-shaking/dead code elimination

juhoteperi21:08:43

Hmph, though ClojureScript side only uses browser, and main so not all fields will work automatically

dnolen21:08:53

@anmonteiro seems almost signed off?

anmonteiro21:08:10

yeah, I think it’s going in if it passes Google internal testing

dnolen21:08:23

I don’t think I’ll have time tomorrow to sort out our own Closure artifact, but it’s still high on my queue

anmonteiro21:08:54

AFAICT they run every commit through their distributed build of every internal project

chrisbroome21:08:00

might be completely off-topic, but has the clojure/clojurescript team thought about targeting WebAssembly as a platform?

dnolen21:08:28

@chrisbroome people ask us that all the time 🙂

dnolen21:08:34

short answer is not anytime soon

chrisbroome21:08:36

yeah i haven't seen any mention of it

dnolen21:08:48

WebAssembly is suboptimal for GCed languages

dnolen21:08:58

in it’s current incarnation anyway

chrisbroome21:08:18

I was reading some about it the other day after webpack said that they got funding to make it a first class module target

chrisbroome21:08:38

it's also kinda cool that the textual representation uses s-expressions 🙂

dnolen21:08:06

I mean supporting WA for modules, seems fine, narrower scope

dnolen21:08:16

but I don’t think we need to even do anything

dnolen21:08:25

somebody write a WA DSL in ClojureScript go have fun