Fork me on GitHub
#announcements
<
2024-06-02
>
Ray Stubbs02:06:37

Announcing the first tagged version of https://github.com/raystubbs/subzero. Build web components in ClojureScript (the easy way). This is the minimal web component and HTML rendering stuff from https://github.com/raystubbs/zero, pulled out into its own lib. In future, Zero will use this lib under the hood, and will focus on state management and utilities rather than the web component implementation. Highlights: • Depends only on the Clojure/Script runtime and browser APIs • Small, simple, easy • Hot reload friendly • Focus-aware virtual DOM reconciliation • 'Good enough' performance with tools for progressive optimization

🎉 16
👍 2
👀 1
Eugen08:06:05

interesting project. I am implementing an app with HTMX at the moment. Exploring HTMX https://htmx.org/ as an alternative to heavy JS apps. One issue I found is sharing of components between app (how do I share a menu or a data grid implementation with pagination, search, etc ). IMO web components offer a solution for this problem but I did not test that assumption yet. I hope to explore it and share my experience. If you have experience with HTMX please consider mentioning / an example on how to use it with Zero / SubZero .

Eugen08:06:28

Also, at first glance I did not see a way to use the components in a plain HTL/JS app . Can that be done?

Eugen08:06:53

@U01CJ79EESY: project looks cool

Ray Stubbs13:06:12

Hi @U011NGC5FFY. I don't have any experience with HTMX, but I do know what it is. Given what little I know about it, I suspect it won't work well if used from within Web Components... but I could be wrong. That said, Web Components themselves are a great way to build your own extended hypertext runtime. At work we were considering using HTMX for a project, but worried we'd hit a wall with its capabilities. Don't need to worry about that with Web Components, since you can add whatever capabilities you need. Yes, Web Components can be rendered via HTML, JS, or whatever other framework you're using. They're used in exactly the same way as you'd use native HTML elements.

Eugen13:06:30

thanks. I'll see we give it a try an share the experience. Regarding the usage, how can I build them to use in a plain html/js project that works without any build tools. I see no docs for that

Ray Stubbs13:06:02

Hmm, it's a ClojureScript library... so you at least need to build the ClojureScript to JS. Just use your regular CLJS build setup for that. Link the build somewhere in your page via <script>. That's it really. Can refer to the first readme example to set things up on the client/CLJS side.

Ray Stubbs14:06:24

The components are added to your browser's custom element registry. So the browser itself does the work of finding them in your DOM and booting everything up.

Ray Stubbs17:06:05

@U011NGC5FFY I added a simple standalone example to demo how it works. It includes a pub/index.html that renders a example-click-counter custom element. https://github.com/raystubbs/subzero/tree/main/examples/click-counter

Eugen17:06:01

thanks, will try it out later. One question: How does :example/click-counter become example-click-counter ? I feel the convention is kind of unexpected

Ray Stubbs17:06:01

There's a name conversion that happens. Basically it's intended to allow us to take advantage of Clojure's namespaced keywords to keep component names tidy. The conversion is (str (namespace k) "-" (munge (name k))). Custom element names are required to include a -, so I think this conversion makes sense. But of course it's not required, you can just use :example-click-counter instead.