This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-08
Channels
- # announcements (6)
- # aws (1)
- # beginners (64)
- # boot (22)
- # calva (9)
- # cider (109)
- # clara (4)
- # cljs-dev (29)
- # clojure (112)
- # clojure-europe (2)
- # clojure-italy (6)
- # clojure-nl (3)
- # clojure-russia (215)
- # clojure-spec (80)
- # clojure-uk (13)
- # clojurescript (150)
- # code-reviews (3)
- # core-async (7)
- # cursive (37)
- # data-science (11)
- # datomic (76)
- # figwheel-main (6)
- # fulcro (56)
- # jobs (3)
- # jobs-discuss (22)
- # juxt (4)
- # off-topic (11)
- # pathom (16)
- # planck (5)
- # portkey (63)
- # re-frame (22)
- # reagent (3)
- # remote-jobs (1)
- # ring-swagger (5)
- # shadow-cljs (3)
- # testing (2)
- # tools-deps (6)
Cool, that worked. Can the index.html file be set to make use of the manifest.edn
mapping to get the correct bundle? Or is it meant to be set manually?
Seems like the idea is to have the build step parse and replace
Ended up writing this hacky thing to run as a lein alias after building the bundles:
(ns build.add-hash
(:gen-class))
(def index-path "./public/index.html")
(def two-hundred-path "./public/200.html")
(def manifest-path "./public/js/manifest.edn")
(def app-js-path "public/js/app.js")
(def app-js-file-to-replace "js/app.js")
(def replacement-regex
(java.util.regex.Pattern/compile app-js-file-to-replace))
(defn -main
"Add hash from the latest package bundle to the html files"
[& args]
(let [manifest (read-string (slurp manifest-path))
hashed-filename (subs (get manifest app-js-path) 7)
index-file (slurp index-path)
adjusted-index (clojure.string/replace index-file
replacement-regex
hashed-filename)]
(do
(spit index-path adjusted-index)
(spit two-hundred-path adjusted-index))))
clj -A:fig -J-Xmx6g
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "../priv/static/js/public/cljs-out/dev-main.js"
[Figwheel] Failed to compile build dev in 2.414 seconds.
[Figwheel] java.lang.StackOverflowError
clojure.lang.PersistentVector/seq at PersistentVector.java(285)
clojure.lang.RT/seqFrom at RT.java(539)
clojure.lang.RT/seq at RT.java(533)
clojure.core$seq__5387/invokeStatic at core.clj(137)
oh man, the reader was just confused over some garbled text in one of the sourcefiles :-0
another question: is there a way to conditionally require a namespace in CLJS? e.g. I want to detect if Datafiable
exists before I require clojure.datafy
While it is possible to check whether a particular var has been loaded from a namespace using tagged literals, the problem is that if your library is required before the other library is required, then it won't detect it. So the problem is, how can you ensure users downstream will load deps in your preferred order?
perhaps conditional loading is the issue? why not have a namespace that loads deps in the correct order
like use my-lib.datafy
when you have datafy
then they dont include your namespace
right so you have a direct dependency on datafy then
then you should be including it as your own dependency
sp why not require clojure.datafy?
I’d like my library to support versions of CLJS that don’t have datafy yet with a fallback
e.g. try to require clojure.datafy in the current version of CLJS 🙂 my library will not work. I don’t know how often people upgrade their CLJS version
using datafy means you would require the latest version
i.e. it wont be cross-version compatible, the best thing to do would be to keep all of the datafy code in a single optional namespace that your library consumer could use if they are also on the latest version
sure you can, but you run the risk of the library-consumer building with an incompatible version of cljs
the thing about using datafy is that it’s not like spec where it’s a separate lib its actually a language feature
the thing to do in this case would be to run 2 versions of your library that build to different language versions
yeah. my library is already split into a set of adapters that can be installed depending on the platform you’re targeting (browser, node, JVM)
maybe I could split this up further. starts to feel kind of a lot if I have e.g. adapter-web
and adapter-web-datafy
, for each platform
oh yeah... clojure.datafy
will always be loaded before library namespaces, so the tagged-literals hack will work for you
Basically, tagged literals run at compile time, like macros, but even before macro expansion, so you can slip them into namespace declarations without breaking their specs
AFAICT custom tagged literals are a PITA to setup in CLJS anyway. I tried it before and couldn’t get it to work
is there a way, on the clojure-side, to detect if an ns is requirable, without causing a compile error when it's not requirable?
So like, in some clojure file my/readers.clj
put:
(defn new? [[then? else?]]
(let [v *clojure-version*
new-enough? (and (<= 1 (:major v)) (<= 10 (:minor v)))]
(if new-enough?
then?
else?)))
Then, in data_readers.cljc
, add this to your map: my/new? my.readers/new?
but I need to detect if the clojurescript version is correct, not the clojure version
hmmm. If you're using a newer version of CLJS that includes datafy, will the clojure version not be recent enough to have datafy? Not sure
and vice versa. I can be on Clojure 1.10 right now, but currently there is no version of CLJS that has datafy 😄
hmm, yeah, even on the latest cljs (git sha, with datafy), if your deps have clojure 1.9, then datafy will be available in cljs but tagged literals will run in an environment with clojure 1.9
This might work:
(defn datafy-exists? [[then? else?]]
(let [opts (-> env/*compiler* deref :cljs.analyzer/constant-table
keys (->> (filter #{'clojure.datafy})))]
(if opts
then?
else?)))
Then, in your my/core.cljs
clojurescript file, do:
(ns my.core
#my/datafy-exists?
[(:require [clojure.datafy :as d]
[cljs.pprint :as pp])
(:require [cljs.pprint :as pp])])
I'll have to see if I can get this to work. last time I tried, I coulnd't get tagged_literal.cljc
to be picked up by shadow-cljs
@lilactown Actually, this works better:
(defn exists? [[extant then? else?]]
(if (-> env/*compiler* deref :cljs.analyzer/constant-table
keys str (clojure.string/split #" ") vec (->> (some #{(str extant)})))
then?
else?))
oh, btw, you could also use this hack to get around having to use split code bases for node/browser/jvm, which I'm pretty sure you can detect through various means at compile time
@chris.schreiner because refreshing is for the birds!
@lilactown that is possible only in clojure, not CLJS
@lilactown but you can set manually by :closure-defines
if you want to load this ns or not. It is what is happening during compilation
I'm not aware of a way to use :closure-defines
to affect whether a particular namespace is required in an ns
form.
[:> TransitionGroup
{:component "div"
:class "list tags collection-view tags-list"
}
(for [tag (state/tags-list state)]
^{:key (:id tag)}
[:> CSSTransition
{:timeout {:enter 250
:exit 150}
:classNames "tag"}
[tag-row tag
(get-in state [:ui/tags (:id tag)])
(:ui/select-all? state)]])]
And the style that goes with it:
[:style
".tag-enter { background-color: transparent;}"
".tag-enter.tag-enter-active { transition: background-color 250ms ease-out; background-color: #FFFF9B;}"
".tag-enter-done { transition: background-color 150ms ease-in; }"
".tag-exit { opacity: 0.7; max-height: 200px;}"
".tag-exit.tag-exit-active { opacity: 0.01; transition: all 150ms ease-out; max-height: 0px;}"
]
Two things — a) you have to wrap things into a TransitionGroup b) you have to give explicit timeouts that match your animations.
I’m using the “community” react-transition-group library, not react-with-addons-whatever. The components themselves have no idea about the animations.
This is only for the case where React will animate deletions/additions to the DOM, I haven’t tried yet anything else.
Is there somewhere I should start when trying to speed up cljs compilation? I enabled compiler-stats but that only gives me 2 compile sources outputs. Is there a more verbose output or some other way to gain insight into what it's spending it's time on? Apologies for lack of code/output examples lmk if these are relevant :)
Another way that seemed to work in the past was to fix the JVM heap size, and not let it float
Ive just enabled parallel builds and knocked off a few seconds, i have compiler stats enabled but I only get
Compile sources, elapsed time: 1921.07242 msecs
Compile sources, elapsed time: 1821.224109 msecs
[Figwheel] Successfully compiled build app to "resources/public/cljs/main.js" in 17.82 seconds.
It would appear it's spending a lot of time doing something else based on this output but I don't know if I'm reading it right.
that looks like you're using an optimization setting to me (if there's that big of a gap)
Sorry for taking a while to post the output had to get it onto my phone :D
Based on my reading of the config it should be optimisations :none, can you query the running app to check?
Some repl fn or something, thanks for the help before I forget.
Found the verbose compiler option, going to give that a go 🙂
In the verbose output in what appears to be the compiler option map I have ups-foreign-libs
with quite a lot of entries. I can't seem to find what that key indicates or if having a lot of entries in there is a problem :)
hello guys
how can i debug these errors:
TypeError: b.Vh is not a function
it's working fine in dev mode but not working in min mode
how can i start fixing this?
the two libs i'm trying to use are: "https://js.braintreegateway.com/web/3.41.0/js/client.min.js https://js.braintreegateway.com/web/3.41.0/js/hosted-fields.min.js
@mbutler foreign libraries don't go through Closure so I don't see how that could be contributing to your compile time
@abdullahibra add the following to your compiler options :pretty-print true :pseudo-names true
Most of the pause/time (about 10s) is taken up before it outputs
Compile sources, elapsed time: 1921.07242 msecs
Does anyone know what kinds of things it (in this case figwheel main) is doing before that? Maybe give me an idea where to look :)
@mbutler which version are you on? it might be indexing node_modules
which can take quite a while.
@thheller 0.1.9. After I save I immediately get the "options passed to cljs compiler" output followed by nothing for 10 secs then some compiler output.
Oh whoops 1.10.339
Okay will do, thanks 🙂
While it is possible to check whether a particular var has been loaded from a namespace using tagged literals, the problem is that if your library is required before the other library is required, then it won't detect it. So the problem is, how can you ensure users downstream will load deps in your preferred order?
how often do people upgrade their version of CLJS in a project they’re maintaining?
I upgrade when my cljs compiler does
currently using shadow-cljs
Hey everyone, I'm having some trouble with clojurescript's stack traces omitting some frames that seem like they ought to be included. Details in thread
Below is my stack trace:
at cljs.core.MapEntry.cljs$core$IIndexed$_nth$arity$2 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:6621:5)
at cljs.core.MapEntry.cljs$core$IFn$_invoke$arity$1 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:6570:1)
at Function.<anonymous> (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/my-project/policy/pos.cljs:115:3)
at Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:3866:8)
at Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$2 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:3861:6)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:3896:6)
at G__11950__delegate (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/my-project/utils/core.cljs:12:5)
at Function.my-project.utils.core.tracefn.G__11950.cljs$lang$applyTo (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/my-project/utils/core.cljs:11:10)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (/my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/core.cljs:3895:10)
at /my-project/.shadow-cljs/builds/test/dev/out/cljs-runtime/my-project/utils/core.cljs:169:48
As you can see, my project only shows up 4 times, though really only the top frame is relevant, since the bottom three are wrappers I've created around functions. However, this was several frames away from where nth
was called, so I replaced a bunch of my defn
s with deftraced
as defined below (clj/cljs files combined for readability):
(def ^:dynamic *trace* [])
(defn tracefn
[n f]
(fn [& args]
(binding [*trace* (conj *trace* n)]
(try
(apply f args)
(catch js/Object e
(when-not (aget e "trace-printed")
(prn *trace*)
(aset e "trace-printed" true))
(throw e))))))
(defmacro deftraced
[sym bindings & forms]
`(def ~sym (tracefn '~sym (fn ~bindings [email protected]))))
This gave me the following trace:
[proxy-inv proxy-inv inv-ctx distribute get-distributed-value proxy-inv inv-ctx distribute]
This was good enough for me to hunt down my bug, but this is a terrible way to debug, and it costs runtime performance. Can anyone explain why I'm seeing only one of 8 function calls in my stack trace, or how to expand the trace so I can see it all? Also note that there's some laziness going on here, but I don't think it's central to my problem, otherwise my custom trace would be shorter.@dnolen i have done this and got more information but i don't know how to proceed with it, can you help please in this, this is my code https://gist.github.com/aibrahim/8090245f967958045e5d6253ca83bc08 and this is js code i try to port to cljs https://codepen.io/braintree/pen/MyzXqG
@abdullahibra Are you familiar with the docs at https://clojurescript.org/guides/externs? You’ll need an externs file to fix this.
ah, worthwhile reading
Thanks I'll read it now then try again and if failed I'll get back here
:thumbsup:
I'm having some issues with self-hosted cljs. When clicking "Eval", I get this error:
TypeError: cljs.core.cst$kw$alt_DASH_impl is undefined
I'm using the approach outlined here: https://stackoverflow.com/a/51575204
You can see the live error here: https://juxt.pro/tick/docs/index.html
I am calling cljs.build.api/build
with {:main
it's a button on the page, it evals the code on page. Source is available at https://github.com/juxt/tick/blob/master/docs/src/tick/docs/app.cljs 🙂
try compiling with :optimize-constants false
though. maybe it defaults to true
for :simple
builds
@thheller bit concerned that you're hitting a 404 for https://juxt.pro/tick/docs/index.html as it seems to work in all my browsers :thinking_face:
oddly though, https://clojurescript.org/guides/self-hosting indicates that optimize-constants should work.