Fork me on GitHub
#clojurescript
<
2020-04-24
>
alex05:04:38

If I have a javascript object that I need to call several JS methods on that mutate the object, is there a threading macro that accomplishes the job?

Oliver George05:04:18

The other related one is essentially the threading macro ..

alex05:04:12

Ah yes, thanks Oliver! doto is what I was hoping for

simongray11:04:11

How do I make a seq out of (.entries (.-classList element)), where element is a DOM element with 1 or more CSS classes applied?I’ve tried with array-seq, but that doesn’t seem to be the right one.

Roman Liutikov11:04:33

(array-seq (.-classList element))

4
simongray11:04:26

Thank you, that did the trick.

Roman Liutikov11:04:09

if you still need a seq of tuples [idx class]

(-> element
    .-classList
    .entries
    js/Array.from
    (->> (map seq)))

Roman Liutikov11:04:33

in upcoming release cljs will have support for es6 iterables

metal 8
simongray12:04:33

As in they will be sequable by default?

Roman Liutikov12:04:15

(seq (js/Set. #js [1 2 3])) will work

simongray12:04:39

nice! That’s gonna make interop a lot smoother.

fricze12:04:48

wow that’s dope

jerger_at_dda15:04:16

Hi, I try to use a js-lib in a shadow-cljs project. The doc says I've to use (ns ... (require ["name-of-lib" :as my-alias])

thheller15:04:48

:require not require

dnolen15:04:18

@jerger_at_dda there's also a very active #shadow-cljs channel

jerger_at_dda15:04:36

(:require ["mastodon-api" :as Mastodon] But repl says failed: Extra input spec: :clojure.core.specs.alpha/ns-form

jerger_at_dda15:04:01

is this shadow-cljs specific?

thheller15:04:25

are you maybe still in the CLJ REPL? which REPL client did you use?

jerger_at_dda15:04:10

I use shadow-cljs node-repl

jerger_at_dda15:04:34

in combination with clava (there are two repl windows after connect)

thheller15:04:07

what is the full ns form you sent and the full error you get?

noisesmith15:04:53

that message means there was a top level form in ns that clojure doesn't know about / understand

noisesmith15:04:05

it wouldn't be :require, but some other key / input in ns

thheller15:04:39

looks fine but if I eval this in a CLJ REPL I get

Syntax error macroexpanding clojure.core/ns at (REPL:2:1).
((:require ["mastodon-api" :as Mastodon] [clojure.pprint :as pprint :refer [pprint]] [cljs.core.async :refer [go]] [cljs.core.async.interop :refer-macros [<p!]])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form

thheller15:04:49

so I'm assuming you are just in a CLJ REPL and not CLJS

jerger_at_dda15:04:58

I know this error from clojure >1.9.0. Spec ist not allowing "mastodon-api"

jerger_at_dda15:04:23

okay, did try to narrow it down

jerger_at_dda15:04:06

@thheller Okay, found the issue. I did

sudo npm install -g shadow-cljs
npm install source-map-support --save-dev
npm install mastodon-api
Start repl results in
shadow-cljs - nREPL server started on port 35019
cljs.user=> SHADOW import error /home/jem/repo/dda/dda-masto-embed/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow.js.shim.module$ws.js
[stdin]:66
    throw e;
    ^
Error: Cannot find module 'ws'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
Installing all modules in user-context solves the issue. Thanx for the hint 🙂

Vishal Gautam17:04:03

new JS bundler support feature is huge! Can’t wait to experiment with this

theeternalpulse01:04:13

Loved the bit echo "{}" > package.json, no you don't have to wade through npm init lol

dnolen17:04:41

new massively simplified Webpack guide https://clojurescript.org/guides/webpack

🎉 20
🎆 8
❤️ 12
dnolen17:04:10

and it's really not specific to Webpack, any JS bundler can work, i.e. Metro etc.

fricze17:04:42

nice stuff :thumbsup:

vlaaad18:04:40

just tried the webpack guide, that's a wonderful experience!

💯 8
Vishal Gautam20:04:05

@dnolen was going through the new guide, its nice but few pieces are missing. Where to include the resources files i.e index.html which serves compiled js files, how to integrate hot code reloading via figwheel. Mentioning these in the guide would be very helpful imo

dnolen20:04:59

@v thanks for the feedback, but the guide is really not the place for that kind of stuff

dnolen20:04:52

we don't talk about other tooling in the guides, but far as I know the changes should be compatible w/ Figwheel I haven't tried myself

dnolen20:04:16

I did chat a bit with @bhauman and he seemed to look forward to the changes, they were made w/ minimal impact in mind

Noah Bogart23:04:02

Anyone have a somewhat recent tutorial on cljs testing that doesn’t bother with frontend stuff? I want to verify my functions do what I expect, I don’t need to make sure it looks right

noisesmith23:04:41

doesn't standard cljs.test do this out of the box, with the same api you'd expect from clojure.test?

noisesmith23:04:11

I guess there's the details like "how to create and initialize the runner"

lilactown23:04:49

yeah that’s right

noisesmith23:04:26

in the past I simply had a page that ran cljs.test/run-tests after requiring all my test cljs namespaces

noisesmith23:04:50

the dom would have pass/failure info, the console would have detailed test runner output

noisesmith23:04:04

... I bet somebody has made a turnkey version of that by now