Fork me on GitHub
#clojurescript
<
2019-01-23
>
ag00:01:16

Has anyone used puppeteer in Clojurescript? Any wrappers? Example projects? Any suggestions are appreciated. Thanks

flyboarder01:01:15

not in cljs, but I am workin on a wrapper for boot

Roman Liutikov01:01:38

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

richiardiandrea02:01:20

Has anyone ever rounded floats in JS (waaat? I know)...the only solution I found is to transform it to exponential representation as string

chrisbroome02:01:59

quick-and-dirty in JS would be

const round = (num, places = 0) => { const factor = Math.pow(10, places); return Math.round(num * factor) / factor}

richiardiandrea02:01:35

Ok great thank you! I though there could be a one function thing but I am being lazy :) maybe Google Closures Library has something

chrisbroome03:01:43

lol no problem. it is a little annoying that there's in standard javascript that does that

chrisbroome02:01:25

probably doesn't get edge cases

chrisbroome02:01:04

that outputs this:

> round(5.23551, 3)
5.236
> round(5.23551, 2)
5.24
> round(5.23551, 1)
5.2

roklenarcic09:01:10

Is there some kind of special thing I have to do to make load-file work in cljs REPL?

roklenarcic09:01:55

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.

fbielejec12:01:30

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.439

erwinrooijakkers12:01:38

From the doc: with-meta only works for Clojure data types implementing clojure.lang.IObj

mfikes13:01:54

ClojureScript should essentially support meta on the same types as Clojure. The analog in ClojureScript is: satisfying IMeta.

erwinrooijakkers13:01:43

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"}

👍 5
erwinrooijakkers13:01:50

I like the “Or just cram the meta in the object to tie its life to the object:”

mfikes13:01:56

Hah. Fortunately, the ability to mutate objects is something I now often forget is a possibility. 🙂

mitch15:01:19

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

borkdude15:01:11

@mitch I have been doing this inside e-mails

5
10
mitch16:01:36

Did you have to use js/FileReader?

dpsutton16:01:24

you don't upload it. you include the bytes in the img tag

dpsutton16:01:22

i thought there was an example in figwheel or in clojurescript somewhere but i'm not seeing it now

😔 5
p4ulcristian17:01:52

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]}

borkdude17:01:37

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)

👍 5
p4ulcristian17:01:06

good enough for me, because my approach has much more of first, second map reduce merge and group-by in it, so thank you 😄

enforser17:01:11

(reduce-kv (fn [m k v]
             (reduce #(update %1 %2 (fnil conj []) k)
                     m
                     v))
           {}
           a)

👍 5
p4ulcristian17:01:28

wow, this one is another level for me, I try to grasp it, but it works very well, thank you 🙂

enforser18:01:37

@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]}))

p4ulcristian18:01:28

I like the first one more, and it is the actual format I needed. And I also almost fully understand it now 🙂

peter-kehl19:01:48

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.

richiardiandrea20:01:09

@peter.kehl Cider does not support Cljs tests, I opened an issue here: https://github.com/clojure-emacs/cider-nrepl/issues/555

👍 5
Jan K21:01:15

Does anyone know a way to find out which namespaces or dependencies are contributing the most volume (JS code size) after advanced optimizations?

thheller21:01:30

shadow-cljs can generate very detailed build reports. https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report

thheller21:01:02

only works for shadow-cljs though

Jan K21:01:11

Thanks, that looks great, I'm not using shadow-cljs at the moment but I guess I'll check it out.

led10:01:28

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

👍 5
thheller10:01:06

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.

thheller10:01:14

shadow-cljs accounts for 100% of the code

ag23:01:52

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?

Roman Liutikov23:01:00

Yes, compile with simple optimisations and use js/require

ag23:01:20

so normal (require) won’t work? ;(

ag23:01:35

someday… maybe someday

Roman Liutikov23:01:19

It works with :none, but I'm not sure if it works for other optimization levels where compiler bundles everything into a single file

ag23:01:16

okay it works… now… how do I get repl and reloaded workflow with deps.edn and clj cli tool?

ag23:01:24

I’m targeting nodejs

ag23:01:51

should I just use figwheel?

valtteri08:01:44

You probably want to look into figwheel-main. It supports hot reloading with node and works nicely with deps.edn. https://figwheel.org/

Roman Liutikov09:01:51

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