clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
lilactown 2020-09-26T00:19:40.045900Z

@ozzloy_clojurians_net you need to dereference the atom inside a component

lilactown 2020-09-26T00:20:22.046900Z

You’re derefing it inside the call to render which doesn’t setup the tracking correctly

victorb 2020-09-26T11:15:22.048400Z

Is there any smaller implementation of pprint suitable for cljs usage? Including clojure.pprint to my application adds about 90KB to the final bundle size, which ends up being like 40% of my application size, but I'd love to be able to pprint in production env as well (currently excluding it for production builds)

skeuomorf 2020-09-26T12:07:40.051600Z

Hey folks, I have been out of the loop with clojurescript for a while, are there any guides out there that list the recommended libraries (that are actively maintained) for the common frontend tasks? Also, do people use things like postcss or are there cljs alternatives? Do people use webpack to get access to all the plugins?

Niclas 2020-09-26T13:34:14.054900Z

Looking for a bit of help from somebody with more knowledge of the inner workings of ClojureScript here, any help appreciated! I’m attempting to enumerate over fn defintions in an ns and fetching each fn’s metadata, however I’m running out of ideas on how to accomplish this. This is as far as I’ve gotten. Is it even possible to do what I’m trying to do?

; in my.ns
  (defn a {:x :a} [])
  (defn b {:x :b} [])
  (:x (meta (var a))) => :a
  (:x (meta (var b))) => :b
  (doseq [f (keys (ns-publics 'my.ns))]
    (meta (var f))) => Unable to resolve var: f in this context...

victorb 2020-09-26T13:36:33.055Z

Re recommendations, everything is pretty opinionated as far as I know. I know some groups "standarized" in just using re-frame + reagent, pulling in npm modules for smaller functionalities as needed. Some of them do inline styling in hiccup, others use a css file, others use styled-component. I haven't myself came across any (cljs) projects using webpack, shadow-cljs/figwheel/figwheel-main handles pretty much every common frontend workflow as far as I know

2020-09-26T13:40:30.056200Z

@looveh You can use (ns-publics ’my-namespace) to get back a map of symbols to var expressions

2020-09-26T13:47:40.059100Z

I am trying to find out if there is a way to prevent the modularization step of compilation. Specifically, what are all the ways cljs.closure/src-file->goog-require is invoked? I can see there is an invocation within src/main/clojure/cljs.repl.cljc’s load-file at line 622, but how about the cases where we just want to make a build, no repl? Thanks for any comment.

skeuomorf 2020-09-26T14:17:50.060Z

Looks like it hasn’t changed much then! Thanks.

schmee 2020-09-26T18:11:51.061Z

hello everyone, I could use some advice to get back into the cljs ecosystem after a long hiatus

schmee 2020-09-26T18:12:16.061600Z

2-3 years ago I built some stuff using “reagent + figwheel + cljsjs”, is that still a viable setup?

schmee 2020-09-26T18:13:22.063100Z

I’ve poked around a bit and now there is shadow-cljs, :foreign-libs and tons of other new stuff, so I’m worried I’m doing something completely outdated

unbalanced 2020-09-28T14:23:52.122200Z

I will say that I am a simple dev and cljs+figwheel+reagent has gotten me very far, even with all the fancy features you mentioned. Here is a little self-inflated demo project that incorporates all of those things: https://github.com/jjtolton/rocinante That being said ... for anything MORE complex than the features I have here... I've been checking out the shadow docs and shadow is killin' it with features.

👍 1
johanatan 2020-09-26T18:13:44.063800Z

does anyone know if it is possible to dynamically construct "qualified keywords" at reader / compile time ? ideally taking the form :ns/class/field

2020-09-26T18:14:32.064400Z

#figwheel and #reagent are definitely still active

schmee 2020-09-26T18:15:23.064900Z

good to hear! if I’m using those two, what would be the “go-to” way to import libraries such as Semantic-UI-react?

schmee 2020-09-26T18:15:45.065500Z

it used to be cljsjs but from what I gather there’s been a lot of change in that space recently

johanatan 2020-09-26T18:15:50.065700Z

(i've tried both a macro and a tagged literal but neither will get evaluated prior to clojure spec's macro expansion time)

johanatan 2020-09-26T18:19:11.066100Z

sub figwheel-main and you're good to go.

johanatan 2020-09-26T18:19:34.066300Z

cljsjs is still the first resort if there is one available

johanatan 2020-09-26T18:19:45.066500Z

the only thing that has changed is npm module consumption

johanatan 2020-09-26T18:21:34.067200Z

here is my reader implementation for details on what i'm trying to accomplish:

(defn read-ns-grouped-keyword [s]
  `(let [[group# kwd#] (clojure.string/split ~s #"/")]
    (keyword (clojure.string/join "/" [~(str *ns*) group#]) kwd#)))

johanatan 2020-09-26T18:22:11.067700Z

used like so: #myns/ns-grouped-keyword "event/type"

johanatan 2020-09-26T18:22:55.068Z

cljs.user=> #myns/ns-grouped-keyword "event/type"
:cljs.user/event/type

schmee 2020-09-26T18:24:01.068100Z

ahh, I did not know there was a new version out, and the Reagent lein template still uses lein-figwheel. Looks like I can use https://github.com/bhauman/figwheel-main-template instead. thanks for the pointer! 🙏

thheller 2020-09-26T18:24:23.068700Z

@johanatan :cljs.user/event/type is not a valid keyword, otherwise just ::event.type will be :current.ns/event.type?

schmee 2020-09-26T18:24:35.068800Z

right! I have very limited knowledge of the broader JS ecosystem (I’m a primarily a Clojure/Java guy), so safe to say I should stick to cljsjs then :thumbsup:

johanatan 2020-09-26T18:50:49.069300Z

it's valid. try it if you doubt me. that's an actual live repl session.

johanatan 2020-09-26T18:51:21.069500Z

i have two requirements here: (name kw) must produce exactly type and it must be qualified by namespace and the word "event"

johanatan 2020-09-26T18:51:42.069700Z

so: :cljs.user_event/type would also satisfy that

johanatan 2020-09-26T18:51:48.069900Z

but aesthetically slash looks better

johanatan 2020-09-26T18:53:00.070200Z

regardless whether you use underscore or slash though, the problem is the same

johanatan 2020-09-26T18:54:48.070400Z

i.e., this is the actual problem: https://clojurians.slack.com/archives/C03S1L9DN/p1601144150065700

dpsutton 2020-09-26T18:55:20.071400Z

Honestly I would go with shadow cljs. It makes npm interop so much easier

johanatan 2020-09-26T18:55:56.071600Z

is that true with the recent cljs npm interop changes though? my understanding is that shadow is outmoded by the cljs way

thheller 2020-09-26T18:56:49.071800Z

I don't understand the problem statement. I looks to me like the slash is the only problem.

thheller 2020-09-26T18:57:16.072Z

::event.type will be fine while ::event/type will look for the event alias which probably doens't exist

thheller 2020-09-26T18:57:54.072200Z

cljs.user=> ::event.type
:cljs.user/event.type

johanatan 2020-09-26T18:58:18.072500Z

(name ::event.type) not= "type"

johanatan 2020-09-26T18:58:22.072700Z

that does not satisfy my requirement

johanatan 2020-09-26T18:58:46.072900Z

these are intended for use with :req-un and :opt-un of spec

johanatan 2020-09-26T18:58:55.073100Z

and spec uses name to get the "name" portion of the kwd

johanatan 2020-09-26T18:59:27.073300Z

the problem statement is that this needs to happen at reader expansion time or macro expansion time (prior to spec's own macro expansion time)

johanatan 2020-09-26T19:00:04.073500Z

cljs.user=> (name ::event.type)
"event.type"
^^ that needs to say just: "type" rather than: "event.type"

johanatan 2020-09-26T19:01:51.074Z

e.g.,

cljs.user=> (name #myns/ns-grouped-keyword "event/type")
"type"

dpsutton 2020-09-26T19:02:03.074200Z

Yes it’s still true in my opinion.

dpsutton 2020-09-26T19:02:48.075500Z

The other way requires setting up bundlers and I’m not sure the best way to do that. With shadow it’s a simple npm install and shadow does everything for you

johanatan 2020-09-26T19:02:52.075700Z

oh yea. you'll want deps.edn rather than lein for sure. much better experience

johanatan 2020-09-26T19:03:15.075900Z

yes the whole point of the cljs changes is to use webpack like the rest of the JS ecosystem does

johanatan 2020-09-26T19:03:25.076100Z

there are tonnes of tutorials on how to set it up

thheller 2020-09-26T19:03:39.076300Z

why does it "need to say that"?

johanatan 2020-09-26T19:03:40.076500Z

but if i were starting a new project at this moment in time, i'd go that route for sure

johanatan 2020-09-26T19:03:57.076900Z

it's a requirement

johanatan 2020-09-26T19:04:12.077400Z

my codebase has a bunch of existing data structures that i'm not keen on changing

johanatan 2020-09-26T19:04:25.077600Z

the word "type" is used across many namespaces

johanatan 2020-09-26T19:04:53.077800Z

i'm trying to retrofit clojure spec to an existing non-optimal (for spec) data model

thheller 2020-09-26T19:05:10.078Z

so the (namespace ::event.type) isn't actually a namespace?

johanatan 2020-09-26T19:05:24.078200Z

correct, it's a "qualification"

johanatan 2020-09-26T19:05:34.078400Z

which is a concatenation of an actual namespace and a "group"

thheller 2020-09-26T19:05:55.078600Z

yeah don't think there is a built-in way to make that happen

johanatan 2020-09-26T19:05:56.078800Z

https://blog.jeaye.com/2017/10/31/clojure-keywords/

johanatan 2020-09-26T19:06:22.079100Z

of course there isn't. hence the question. i wouldn't be exploring macros and tagged literals if there were a built in way

thheller 2020-09-26T19:06:44.079300Z

well maybe you should explore a custom spec impl 😛

johanatan 2020-09-26T19:06:58.079500Z

the multi-spec section of this page uses a "non-namespace, qualified keyword": https://clojure.org/guides/spec

johanatan 2020-09-26T19:07:02.079700Z

e.g.

johanatan 2020-09-26T19:07:13.079900Z

i.e., :event/type is a non-namespaced, qualified keywor

thheller 2020-09-26T19:08:09.080100Z

I wrote an impl a long time ago that works on "unqualified maps" directly and not via spec :req-un

thheller 2020-09-26T19:08:58.080600Z

definitely do not use that implementation but maybe something in that direction works better for your usecase?

johanatan 2020-09-26T19:09:38.080800Z

i'm afraid i'd have to reimplement a lot. it'd be basically the whole "multi-spec" section of that clojure guide

thheller 2020-09-26T19:10:24.081200Z

mutli-spec works just fine with this?

johanatan 2020-09-26T19:11:07.081600Z

works just fine with what?

thheller 2020-09-26T19:11:17.081800Z

https://github.com/edn-format/edn#symbols

thheller 2020-09-26T19:11:59.082200Z

/ has special meaning in symbols. It can be used once only in the middle of a symbol to separate the prefix (often a namespace) from the name

johanatan 2020-09-26T19:12:13.082400Z

i'm not using edn and this isn't really a symbol

johanatan 2020-09-26T19:12:17.082600Z

it's a qualified keyword

johanatan 2020-09-26T19:12:29.082800Z

but once again if you really quibble over the "/", it can be a "_"

johanatan 2020-09-26T19:12:34.083Z

no harm no foul

johanatan 2020-09-26T19:13:32.083200Z

spec doesn't care about the difference between: :event/type and :my-ns_event/type

johanatan 2020-09-26T19:13:48.083400Z

the latter is to prevent collisions between namespaces

thheller 2020-09-26T19:14:59.083700Z

I'm not trying to quibble over anything. I'm pointing out that you are actively trying to fight the system and namespace and names. nothing in clojure will let you do that easily. of course you can do so but I would still warn you strongly against doing so since it will most likely need to more trouble in the future somewhere

johanatan 2020-09-26T19:15:18.083900Z

ok, so then "_" it is

johanatan 2020-09-26T19:15:21.084100Z

no fight, yes?

johanatan 2020-09-26T19:15:31.084300Z

now you can join me where I'm at without objection

johanatan 2020-09-26T19:16:13.084500Z

there is "no fighting the system". there is only "dynamically creating qualified keywords at reader/compile time"

johanatan 2020-09-26T19:16:21.084700Z

which is precisely what my original question pertained to

thheller 2020-09-26T19:16:27.084900Z

I thought you solved that with the reader fn?

johanatan 2020-09-26T19:16:35.085100Z

no, the problem is that it works in the repl

johanatan 2020-09-26T19:16:44.085300Z

but in source code, it just gets expanded

johanatan 2020-09-26T19:16:46.085500Z

not eval'd

johanatan 2020-09-26T19:16:54.085700Z

and then spec complains that it received a "form"

johanatan 2020-09-26T19:16:57.085900Z

rather than a keyword

johanatan 2020-09-26T19:17:08.086100Z

and the fact that cljs has no "eval"

johanatan 2020-09-26T19:17:17.086300Z

prevents me from actively "evaluating" it myself

thheller 2020-09-26T19:17:31.086500Z

reader fns are eval'd at read-time not at runtime?

thheller 2020-09-26T19:17:45.086700Z

ah ...

johanatan 2020-09-26T19:17:48.086900Z

that's not what i'm seeing in practice. looks like they are merely expanded

thheller 2020-09-26T19:18:01.087100Z

you are returning a form in your reader fn

thheller 2020-09-26T19:18:08.087300Z

skip the leading backtick 😛

thheller 2020-09-26T19:18:16.087500Z

just return the keyword instance

johanatan 2020-09-26T19:18:22.087700Z

hmm, i thought that would work but i got a weird crash when i tried that

johanatan 2020-09-26T19:18:30.088Z

let me try again

johanatan 2020-09-26T19:19:27.088200Z

(that was how all examples I've seen do it so I figured it must be part of the contract)

johanatan 2020-09-26T19:19:45.088400Z

i.e., all examples return forms not instances

thheller 2020-09-26T19:22:03.088600Z

well yeah but the keyword is the form you want?

johanatan 2020-09-26T19:22:15.088800Z

hmm, looks like you may be right

johanatan 2020-09-26T19:22:19.089Z

i think it's working!

johanatan 2020-09-26T19:22:22.089200Z

🙂

johanatan 2020-09-26T19:26:42.089400Z

doh!

johanatan 2020-09-26T19:26:46.089600Z

yep, it's definitely working

johanatan 2020-09-26T19:26:59.089800Z

thanks for your help!

johanatan 2020-09-26T19:28:17.090Z

my repl must have been in some weird state or some other problem was interfering when I tried this yesterday

johanatan 2020-09-26T19:28:33.090200Z

2nd time's a charm apparently

johanatan 2020-09-26T19:30:36.090500Z

one other weird thing though. the compiler actually complains about my data_readers.cljc. about both "no such namespace" and "undeclared var". seems spurious as the actual code works fine at runtime

victorb 2020-09-26T20:34:21.091200Z

I'm not sure deps.edn rather than leiningen is a "for sure" yet. I haven't found a feature of deps.edn that isn't already supported by leiningen. Only thing I can think of is that deps.edn is more "blessed" by the core clojure team

johanatan 2020-09-26T20:35:43.092300Z

It’s far less noisy / more concise. Plug-in system is far simpler / less buggy.

johanatan 2020-09-26T20:36:01.092900Z

Built-in support for git sha refs

johanatan 2020-09-26T20:36:16.093300Z

In general it “just works”

johanatan 2020-09-26T20:36:31.093900Z

And that most definitely isn’t the case for the complicated leiningen

victorb 2020-09-26T20:37:39.094100Z

yeah, generally (in my experience, not doing anything too fancy), leiningen "just works" too. Hence the uncertainty around you using "for sure". I don't mind what you use, but plenty of the ecosystem still uses leiningen, for what's it worth

johanatan 2020-09-26T20:38:18.095100Z

I’m just giving my opinion. I’ve used both heavily and there’s just no comparison. Feel free to disagree

👍 1