cljs-dev

dnolen 2024-12-23T12:26:54.044559Z

after a lot of notes, I'm feeling slightly less good about js js$ - also just not loving goog$global nor globalThis etc. as a convention. One thing that would be nice is if for global stuff we can maintain the convention of a proper namespace instead of the js/ workaround.

dnolen 2024-12-23T12:27:30.932859Z

any thoughts about (:require [cljs.host :refer [HTMLElement]]) ?

dnolen 2024-12-23T12:28:39.895119Z

I think it's worth coming up w/ something that is nice to look at - whatever we go w/ - we're gonna be stuck w/ it

borkdude 2024-12-23T12:28:46.281589Z

I think I would prefer (:require [globalThis :refer [HTMLElement]]) instead, instead of a nested namespace name

borkdude 2024-12-23T12:29:19.611239Z

and then (:require [globalThis$React :as react]) would also work (since $ is already a feature)

dnolen 2024-12-23T12:29:32.237689Z

I don't like globalThis - nested namespace is not an issue for ClojureScript programmers

dnolen 2024-12-23T12:29:50.955319Z

single segment namespaces always -1

borkdude 2024-12-23T12:30:05.069339Z

yes, but in this case, it's a special thing, not a real namespace

dnolen 2024-12-23T12:30:39.320929Z

but that is the difference in what I'm proposing, cljs.host we could preserve namespace semantics

dnolen 2024-12-23T12:31:08.091429Z

cljs.host/HTMLElement etc. - which is natural, in the case of globalThis would have to special case

borkdude 2024-12-23T12:31:37.170279Z

ok. will cljs.host$React also still work (like with JS libs)?

dnolen 2024-12-23T12:31:57.804349Z

everything would work - under the hood cljs.host is just globalThis

borkdude 2024-12-23T12:32:15.317499Z

I mean (:require [cljs.host$React :as react])?

dnolen 2024-12-23T12:32:33.292979Z

yes, the intent would be to support all features

borkdude 2024-12-23T12:32:54.088149Z

cool. that's the most important one to me personally. cljs.host feels a bit weird, but I could live with it

dnolen 2024-12-23T12:34:16.292109Z

other things that would just work is that cljs.host.React/Element w/o :require the way that goog.string does etc.

borkdude 2024-12-23T12:36:34.272509Z

wait, weren't we supposed to always require goog.* stuff since a few releases back?

dnolen 2024-12-23T12:39:07.759289Z

well, that's because of the google.module misfeature

dnolen 2024-12-23T12:39:15.785369Z

but also now we control GCL 🙂

dnolen 2024-12-23T12:39:57.698149Z

only GCL modules have that restriction

dnolen 2024-12-23T12:40:37.396259Z

in anycase, this isn't really a feature to highlight for CLJS-3233 - just pointing out that more Clojure semantics get coverage here

thheller 2024-12-23T15:14:18.828749Z

I disklike this variant very much. it should have clearer rules and the placement of the / should not be arbitrary. not exactly a fan of / in the first place. not sure if current specs even allow qualified symbols there

thheller 2024-12-23T15:15:15.316189Z

if anything cljs.host/React.Element and not cljs.host.React/Element

thheller 2024-12-23T15:16:04.191269Z

making cljs.host a special "namespace" is fine, although honestly it might as well be js/ then since we already have that

👍 1
borkdude 2024-12-23T15:16:30.070529Z

I think not having this in :require would just unnecessarily complicate tooling (and the analysis in the compiler itself) anyway?

thheller 2024-12-23T15:18:49.574099Z

hmm?

borkdude 2024-12-23T15:18:49.779499Z

I agree with @thheller that I would find js more clear as well since this symbol is already in use for the global JS environment

borkdude 2024-12-23T15:19:44.913599Z

@thheller I meant, I'd prefer writing (:require [cljs.host$React :as react]) + react/Element instead of cljs.host.React/Element anyway

thheller 2024-12-23T15:21:15.447199Z

I think there is value in having (:require [js/some.global.Thing :as x]) for (x/something) as opposed to the alternative of just (js/some.global.Thing.something) which gets tedious if there are repeated uses and (def x js/some.global.Thing) forces (.something x) syntax or the somewhat accidental (x.something)

borkdude 2024-12-23T15:21:35.585169Z

yes, that's what I was saying :)

thheller 2024-12-23T15:21:55.228089Z

(:require [cljs.host/some.global.Thing :as x]) is just a new thing for no real reason I can think of

borkdude 2024-12-23T15:22:01.282029Z

but this should be js$some.global.Thing in the :require imo since $ is already supported

thheller 2024-12-23T15:22:24.376869Z

js/ has precedence for many years now and it just extended to work in ns

borkdude 2024-12-23T15:24:22.398299Z

that's a valid point although why introduce more syntax in ns for something that already exists (for accessing stuff from js libs)

borkdude 2024-12-23T15:25:29.840649Z

it also goes against the clj JVM spec whereas $ doesn't:

user=> (ns foo (:require [js/bar :as z]))
Syntax error macroexpanding clojure.core/ns at (REPL:1:1).
((:require [js/bar :as z])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
user=> (ns foo (:require [js$bar :as z]))
Execution error (FileNotFoundException) at foo/eval136$loading (REPL:1).
Could not locate js$bar__init.class, js$bar.clj or js$bar.cljc on classpath.

thheller 2024-12-23T15:27:00.435149Z

$ is very meh to be honest. will lead to question as to why js$thing doesn't work in other places and has to be js/thing there

thheller 2024-12-23T15:27:25.327729Z

but yeah the spec thing might be blocker

borkdude 2024-12-23T15:27:29.549209Z

or it will lead to: hey I can use $ for normal libs too ;)

dnolen 2024-12-23T15:34:48.612359Z

sorry if I wasn't clear, we're not allowing / in (:require ...)

dnolen 2024-12-23T15:36:23.285109Z

I was just talking about the fact that say you have a library loaded in the global environment, if you are lazy (which you should not be) - you can write cljs.host/React or cljs.host.React/Element as a var reference in a source file.

dnolen 2024-12-23T15:42:32.070249Z

again I'm not talking about this is as some kind of big feature, rather just more generally pointing out that the behavior is more aligned w/ a namespace than what js/ gives us today which is kinda weird.

dnolen 2024-12-23T15:45:00.223359Z

w/ js it's just hard to deliver the expected "symmetry" here

dnolen 2024-12-23T15:45:28.711689Z

i.e. (:require [js$React ...]) whell js$React is a namespace so why not js$React/Element var ref in a source file?

dnolen 2024-12-23T15:46:17.032599Z

if you take it to its logical conclusion - I hit this when writing down my notes - that's how I ended up at cljs.host idea

dnolen 2024-12-23T15:52:34.090859Z

similar thoughts about (:require [$React ...]) why not $React/Element in a source file - I just don't this looks very good over a proper namespace for this stuff to go that isn't single segment.

thheller 2024-12-23T15:53:39.671699Z

$foo is a normal symbol and I have used such names in many places. making them somewhat magical now would break stuff.

borkdude 2024-12-23T15:53:53.768389Z

why not js$React/Element 
why not $React/Element in a source file
because those aren't known as aliases introduced in the ns form

dnolen 2024-12-23T15:54:05.855679Z

yes, so this is why I don't like the $Foo shorthand

dnolen 2024-12-23T15:54:23.124109Z

anyways, it's really worth pondering the benefits of typing a little bit more here.

dnolen 2024-12-23T15:54:35.788749Z

no one can take cljs.host except for ClojureScript

dnolen 2024-12-23T15:55:45.470269Z

because those aren't known as aliases introduced in the ns form this is an after the fact explanation of this won't work.

dnolen 2024-12-23T15:55:58.308799Z

so a strike against shorthands in the (:require ...) form

dnolen 2024-12-23T15:57:41.171869Z

another way to evaluate what I'm proposing

dnolen 2024-12-23T15:57:58.308899Z

1. All Closure / ClojureScript / global things follow the namespace conventions

borkdude 2024-12-23T15:58:09.784219Z

huh? all I meant was that a in a/x in general should be an alias (introduced by the ns form) or class (`:import`) I wasn't saying anything about how that alias was introduced. either js$Foo or cljs.host$Foo could work, but this is unrelated

dnolen 2024-12-23T15:58:18.926659Z

2. Only foreign JS deps lose out

dnolen 2024-12-23T15:58:57.628429Z

because of the module thing

dnolen 2024-12-23T16:02:12.408129Z

to be extra clear - what I'm talking about is not just the syntax in the :require form, but also how you reference vars in source files because these are related.

borkdude 2024-12-23T16:03:11.943729Z

Perhaps an excel sheet with the options would make it clearer what you're saying, a la Rich Hickey Design in Practice :)

dnolen 2024-12-23T16:13:47.682479Z

sure I think that will help, will put one together and post it

❤️ 1
p-himik 2024-12-23T12:34:34.540549Z

I imagine it would be slightly easier for people to provide cljs/host.clj for mocks for testing their CLJC code on the backend. Not sure how important or desirable it is though.

dnolen 2024-12-23T12:34:36.442029Z

so this really about bending all this global stuff into Clojure(Script) expectations