This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-23
Channels
- # aleph (1)
- # architecture (4)
- # aws (7)
- # beginners (249)
- # boot (17)
- # calva (4)
- # cider (30)
- # cljdoc (7)
- # cljs-dev (1)
- # cljs-experience (3)
- # clojure (69)
- # clojure-dev (7)
- # clojure-europe (1)
- # clojure-italy (7)
- # clojure-japan (15)
- # clojure-spec (6)
- # clojure-uk (39)
- # clojurescript (51)
- # cursive (31)
- # data-science (4)
- # datavis (1)
- # datomic (40)
- # dirac (67)
- # duct (8)
- # editors (15)
- # emacs (9)
- # events (3)
- # figwheel-main (2)
- # fulcro (157)
- # juxt (4)
- # kaocha (11)
- # lein-figwheel (1)
- # off-topic (31)
- # pathom (18)
- # re-frame (4)
- # reagent (2)
- # reitit (16)
- # remote-jobs (1)
- # shadow-cljs (11)
- # specter (2)
- # speculative (1)
- # tools-deps (27)
- # vim (1)
- # yada (2)
Has anyone used puppeteer in Clojurescript? Any wrappers? Example projects? Any suggestions are appreciated. Thanks
not in cljs, but I am workin on a wrapper for boot
Puppeteer API is very straightforward, I don't think you even need a wrapper. core.async might be enough to handle sequences of async ops
Has anyone ever rounded floats in JS (waaat? I know)...the only solution I found is to transform it to exponential representation as string
quick-and-dirty in JS would be
const round = (num, places = 0) => { const factor = Math.pow(10, places); return Math.round(num * factor) / factor}
Ok great thank you! I though there could be a one function thing but I am being lazy :) maybe Google Closures Library has something
lol no problem. it is a little annoying that there's in standard javascript that does that
Indeed
probably doesn't get edge cases
that outputs this:
> round(5.23551, 3)
5.236
> round(5.23551, 2)
5.24
> round(5.23551, 1)
5.2
Is there some kind of special thing I have to do to make load-file
work in cljs REPL?
dev:cljs.user=> (load-file "/Users/roklenarcic/clojure-projects/myproject/src/cljs/myproject/panels.cljs")
clojure.lang.ExceptionInfo: myproject.routes does not exist #:cljs.repl{:error :invalid-ns}
I'm using the figwheel.I just ran into this:
(def fubar "fubar")
^{:foo :bar} fubar
(with-meta fubar {:foo :bar})
;; => #object[Error Error: No protocol method IWithMeta.-with-meta defined for type string: fubar]
cljs 1.10.439From the doc: with-meta
only works for Clojure data types implementing clojure.lang.IObj
ClojureScript should essentially support meta on the same types as Clojure. The analog in ClojureScript is: satisfying IMeta
.
You could do something like this:
cljs.user=> (def meta-storage (atom {}))
#'cljs.user/meta-storage
cljs.user=> (extend-type string IWithMeta (-with-meta [o meta] (swap! meta-storage assoc o meta)) IMeta (-meta [o] (get @meta-storage o)))
nil
cljs.user=> (with-meta fubar {:foo "bar"})
{"fubar" {:foo "bar"}}
cljs.user=> (meta fubar)
{:foo "bar"}
Here is another take on that idea https://gist.github.com/mfikes/122814757fd1f2aec9de509446793e5f
I like the “Or just cram the meta in the object to tie its life to the object:”
Hah. Fortunately, the ability to mutate objects is something I now often forget is a possibility. 🙂
Anyone have any experience uploading an image file and encoding it to b64 so you can use it in a [img :src] as a data url? Can't seem to figure this one out
This one should help you https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
i thought there was an example in figwheel or in clojurescript somewhere but i'm not seeing it now
what is the easiest way to make {:a [1 2 3] :c [3 4 5] :d [1 3 6]}
to {1 [:a :d] 2 [:a] 3 [:a :c :d] 4 [:c] 5 [:c] 6 [:d]}
this comes close:
(def d {:a [1 2 3] :c [3 4 5] :d [1 3 6]})
(def pairs (for [[k vs] d
v vs]
[k v]))
(group-by second pairs)
good enough for me, because my approach has much more of first
, second
map
reduce
merge
and group-by
in it, so thank you 😄
wow, this one is another level for me, I try to grasp it, but it works very well, thank you 🙂
@paul931224 here's a slight modification of the one with for
to get the actual format you wanted back. IMO this looks a little cleaner, but it's also not as fast as the reduce solution.
(apply merge-with concat (for [[k vs] a
v vs]
{v [k]}))
I like the first one more, and it is the actual format I needed. And I also almost fully understand it now 🙂
Hi team.
I have cider
running figwheel.
How can I invoke CLJS tests, please?
I've run CLJ test by lein test
before, but not from REPL neither from CLJS.
Plus now I use deps.edn
instead of lein.
@peter.kehl Cider does not support Cljs tests, I opened an issue here: https://github.com/clojure-emacs/cider-nrepl/issues/555
Does anyone know a way to find out which namespaces or dependencies are contributing the most volume (JS code size) after advanced optimizations?
shadow-cljs can generate very detailed build reports. https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report
Thanks, that looks great, I'm not using shadow-cljs at the moment but I guess I'll check it out.
One slightly indirect option is to generate a sourcemap of your code then view that with source-map-explorer https://www.npmjs.com/package/source-map-explorer
unfortunately that will be pretty inaccurate for CLJS builds since CLJS by default does not have any source maps for :foreign-libs
aka cljsjs
. So you'll only get maps for the CLJS portions which large gaps for foreign code.
if I remember it right (sorry it’s been awhile) it is possible to require a dependency straight from node_modules if the compilation target is nodejs, right?
Yes, compile with simple optimisations and use js/require
It works with :none, but I'm not sure if it works for other optimization levels where compiler bundles everything into a single file
okay it works… now… how do I get repl and reloaded workflow with deps.edn and clj
cli tool?
You probably want to look into figwheel-main
. It supports hot reloading with node and works nicely with deps.edn. https://figwheel.org/
I find it easier to restart node process on every change, mainly because Node stuff is stateful and it’s just easier to restart the world