Fork me on GitHub
#clojurescript
<
2017-11-11
>
mfikes00:11:04

@dpsutton You can convert from a transit UUID to a core UUID by first converting to string:

cljs.user=> (require '[cognitect.transit :as t])
nil
cljs.user=> (uuid (str (t/uuid "123e4567-e89b-12d3-a456-426655440000")))
#uuid "123e4567-e89b-12d3-a456-426655440000"

mfikes00:11:31

Interestingly, there is code in Transit supporting the intent that Transit UUIDs and core UUIDs be transparently exchangeable, but the new core uuid? function was written after all of that and doesn't address that aspect.

mfikes00:11:46

@dpsutton Looks like you can fix uuid? failing on Transit UUIDs by revising them to implement IUUID. Hrm.

cljs.user=> (require '[com.cognitect.transit.types :as ty])
nil
cljs.user=> (extend-type ty/UUID IUUID)
#js {}
cljs.user=> (uuid? (t/uuid "123e4567-e89b-12d3-a456-426655440000"))
true

mattly00:11:28

I’m getting an error I haven’t seen before while attempting to use a cljsjs dependency to a new project: java.io.FileNotFoundException: Could not locate cljsjs/aws_sdk_js__init.class or cljsjs/aws_sdk_js.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

mattly00:11:53

the js files from cljsjs are in the right place, but it seems the cljs compiler is trying to load these as a java class for whatever reason

mfikes00:11:08

@mattly You would get that if you are requiring them as macros. In other words (require-macros 'cljsjs.aws-sdk-js) repros that error.

mattly00:11:31

I’m on clojurescript 1.9.946

dpsutton00:11:40

I figured there was something like that out there. Thanks @mfikes

mfikes00:11:22

@dpsutton No problem. Perhaps transit-cljs should automatically (extend-type ty/UUID IUUID) in its core namespace.

dpsutton00:11:51

Yeah I'm a little surprised it didn't hide itself a little better

mfikes00:11:00

@mattly Is myapp.states.login perhaps a .cljc file that requires macros from itself?

mfikes00:11:22

@dpsutton I think the intent is to hide the difference, but that was coded up 3 years ago, with uuid? being relatively new.

mattly00:11:48

@mfikes it uses re-frame, but that’s the only other entry in :require and there’s no macros at all

mfikes00:11:22

@mattly Is there a stack trace associated with the error? Perhaps it has a hint as to where things go into Clojure-land.

mattly00:11:57

hm… the error is coming from Figwheel in the browser, not anywhere else afaict

mattly00:11:07

lemme try lein cljsbuild

mattly00:11:20

I’m also unfamiliar with lein, I’ve used mostly boot in the past

mfikes00:11:42

Ahh, Figwheel is only showing the error message, without the stacktrace? Dang.

mattly00:11:14

ok here’s the error from cljsbuild:

mfikes00:11:54

@mattly Yeah, it definitely looks like you have a *.cljc file that is being loaded by Clojure instead of by ClojureScript

mattly00:11:08

hm, perhaps I should double-check my source paths

mfikes00:11:39

@mattly On the surface, I don't think paths would be the root cause (all source files need to be "on the classpath" somewhere but that doesn't control how they are treated / loaded)

mfikes00:11:16

The fact that the error starts off with Reloading Clojure file is interesting...

mfikes00:11:58

@mattly Perhaps you are onto something though, especially if it is in the "env/dev/myapp" directory

mfikes00:11:10

(`dev` would be treated specially, I think)

mfikes00:11:01

Need, to run, but my guess above, with dev is that stuff in that directory might be loaded like user.clj would be loaded. In other words, it may have special meaning to lein.

mattly00:11:34

there’s actually nothing in the /env/dev directory I’m using yet, I’m going to try removing that

mattly00:11:47

cljsbuild works, but figwheel still fails

mattly01:11:07

this seems to be specifically a figwheel problem now, I can cause a similar error with a (js/console.log :foo) call

mattly01:11:03

it’s fine until I reload something

mfikes01:11:37

Yeah, that code is evidently being compiled as Clojure, not ClojureScript.

mattly01:11:39

it should have been a .cljs file, not .cljc

mattly01:11:04

definitely time to go home

Kevin Lynagh02:11:24

Is it possible to pass feature flags to the reader used by the cljs compiler? Motivating use case described here: https://gist.github.com/lynaghk/0608a43f173558b6fcf30c3be53d77dd

thheller08:11:06

@kevin.lynagh nice timing. I was going to open a ticket about that very thing. My current plan was to add :reader-features #{:kw1 kw2} to the build config and use that when reading .cljc files. My goal however was to enable reading based on the target platform, eg. node, browser, react-native, etc.

Kevin Lynagh00:11:40

@thheller Interesting. Thanks for opening up a JIRA ticket. This looks like a straightforward technical change, but I haven't thought about broader community issues w.r.t. language fragmentation, conflicting conditional reads in transitive dependencies, etc.

Kevin Lynagh00:11:10

So I can't say I'm certain it's a good idea, just that it'd solve my immediate problem. I'm curious to see what discussion happens on that ticket.

thheller08:11:32

but splitting dev code from release code is also a good use-case I guess

roti09:11:49

has anyone done some debouncing with react? (do something only after event stopped occuring, like trigger the search when the user stopped typing)

rauh10:11:24

@roti use [goog.async Debouncer] and then set it up in will-mount and tear down in did-unmount

roti10:11:10

@rauh thanks. what should happen on unmount?

rauh10:11:19

@roti (.dispose db)

metametadata14:11:43

@kevin.lynagh I think you could use :external-config and some helper macros to exclude values on dev builds. Here's the example: https://gist.github.com/metametadata/bb00917e09463f6ce04f0e50ccc0740a cc @thheller

thheller19:11:25

but you can’t do conditional requires this way.

metametadata20:11:47

@thheller I'm not sure it's really needed in this case as hopefully Closure's DCE will kick in and core.spec will not end up in the produciton build.

thheller20:11:57

that is unfortunately incorrect. cljs.spec is very unfriendly towards DCE. It pretty much can’t be removed at all.

metametadata20:11:42

huh, didn't know that, thanks

metametadata20:11:19

I didn't try it but maybe (when-debug (require ...)) could work

thheller20:11:04

require is only allowed at the top-level. so it can’t be conditional.

metametadata20:11:58

okay, thanks. I'll upvote the the bug you issued 🙂

mfikes17:11:15

@kevin.lynagh If you can use 1.9.854 or later, you can rely on aggressive branch elision that occurs at the ClojureScript level for ^:const Boolean Vars. This can remove stuff that even goog.DEBUG fails to ferret out. Details here https://gist.github.com/mfikes/93cb77921ee35c2328b92af441ee5393

metametadata20:11:57

@mfikes I guess your solution (as well as :external-config one) also won't help with eliminating the require of core.spec as @thheller pointed out in the above thread, due to https://dev.clojure.org/jira/browse/CLJS-1701?

mfikes20:11:07

@metametadata In the test I was doing, simply requiring clojure.spec.alpha results in no increase in generated code size under :advanced.

mfikes20:11:44

Perhaps thing have improved—I was using the latest ClojureScript release.

thheller20:11:59

hmm maybe something changed since I tested it, it has been a while. just a single spec will probably keep everything alive though.

mfikes22:11:37

I went back and checked, and was incorrect. Simply requiring cljs.spec.alpha increases my :advanced uncompressed output by 8 kB.