This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-27
Channels
- # announcements (4)
- # beginners (41)
- # biff (8)
- # cider (14)
- # clj-kondo (5)
- # clojure (45)
- # clojure-brasil (1)
- # clojure-europe (20)
- # clojure-nl (1)
- # clojure-norway (30)
- # clojure-uk (10)
- # clojurescript (8)
- # cursive (25)
- # datomic (20)
- # emacs (11)
- # events (1)
- # hoplon (9)
- # humbleui (7)
- # hyperfiddle (6)
- # lsp (63)
- # matrix (1)
- # observability (20)
- # off-topic (36)
- # polylith (11)
- # re-frame (2)
- # releases (1)
- # rewrite-clj (6)
- # scittle (42)
- # sql (6)
- # squint (86)
- # tools-deps (9)
Maybe something like this will be an interesting application for Squint. Nothing fancy, just tiny PoC https://jsfiddle.net/jeroenvandijk/ygrnpx8h/8/
<div hc-on:click="(-> el (_closest :div) _remove)">
click to remove me ....
</div>
TLDR; hyperscript/htmx like with squint. See fiddle for live demoit should work
show/?editor_console=:183 Uncaught ReferenceError: htmx is not defined at show/?editor_console=:183:24
oh wait hmm
can't see what is off. Works here in a fresh incognito browser window. Tried Chrome and Brave
before and after 🙈
Yeah it think so too :face_with_hand_over_mouth: Probably needs some good API design and real life testing. But I like the idea i think
It should be below the html. I was hiding it for the wow effect
Here is the whole snippet
haha oh oops 😅
I also didn't know a better way to expose an api to the squint context, but it works this way. Maybe it would be good to have some namespaces for the htmx functions and maybe a threading macro to not having to repeat that namespace. Maybe some experienced htmx users have an opinion, i'm not there yet
you can use the repl output in the newest squint versions to emit "namespaces" as global objects
not yet, thanks! now just sharing this brainfart. Maybe I'll try it a bit for real later
I was also thinking about this a few days ago! The idea I had also involved something like the following on the server side
[:button {:onclick (squint (js/alert "test")))} "test"]
I.e. the squint code lives inside the server code and gets compiled on the fly. That way you have full syntax support (no code in a string stuff) and with clj-kondo we there could even be a linter that has a special understanding of those formsAnd then there could be a tiny support lib like what you used in your example @U0FT7SRLP
Nice @U050TNB9F! I think the native onclick cannot be used nicely because the element is not passed to the function (so you don't know where you are without hacks). I think that's why hyperscript has an edge for instance. But yeah lot of options
Also, a custom attribute also has the advantage of allowing a custom treatment. So you can assume a certain format, context etc. With onclick it has to be javascript. I guess some tradeoffs here
"I think the native onclick cannot be used nicely"
I guess you could make a convention of what the el
thing is or so
Ah yeah, totally could use a different attribute, I didn't really think to far about it. I just really liked the prospect of having an actual syntax in your editor (and lint that even)
Yeah sounds good, i think it is nice that squint allows to experiment with both. So it would also work for people that don't have a clojure(script) setup
> I guess you could make a convention of what the el
thing is or so
Yeah in case you mean the naming, for sure. But I could not find a way to get access to the current dom element with the normal onclick
. this
seems to be the window
in e.g. <button onclick="console.log(this)">click</button>
from the top of my head
With addEventListener
you can do this.target
and get the element from which you can to the parent etc
sorry i mean the argument to the function, not this
now only a question of how to compile that 😄
why not just [:div {:onclick (squint ...)]
which is regular hiccup where squint can be the macro?
This is what this does here
[:div {:onclick "function(e){console.log(e)}"} "hi"]
->
<div onclick="function(e){console.log(e)}">hi</div>
->
Uncaught SyntaxError: Function statements require a function name (at squint.html:31:231)
ah but i ran into this before 🙂
you can wrap it with another function and then it works too
yeah i think that's the problem. I was just verifying if i missed something, but yeah that's the reason
so the snippet doesn't give you the current element. Which is what you want often. Maybe you could do a lookup, but that might be expensive?
(like parsing and searching for it?)
Perhaps you could compile to:
(fn [this] (-> ...)) => (this-as this ((fn [this] ...) this)
yeah indeed. But this only works if you add if via node.addEventListener('click', function(this) { ... })
I think
ok this is something I don't know I guess
but would be nice
this-as
comes from clojurescript? It feels familiar
I think in the end the squint
macro or whatever would need to inject compiled JS into the runtime, it probably won't work to emit the compiled JS into an HTML attribute 😄
ok maybe i just missed something or missed one step. I was wrong you have access to this
in the onclick
. Never mind the above 🙈
right, so you could have:
{:onclick "(this-as this ((fn [this] ...) this))"}
but generate the this-as wrapping for the user so the user only writes:
(fn [this] ...)
maybe, but it'll hurt readability, probably makes it hard to debug etc. no? I'd think emitting a <script>
tag would be a bit more "in line"
if you compile it with squint you could wrap this
in the context? No need for this-as
? We don't need the function wrapping at all i think. I was wrong here
ah maybe that's what I ran into
I had the wrong assumption that htmx and hyperscript were using custom attributes because of the lack of access to this, but that is not the case. But a custom attribute does allow custom treatment, with onclick it needs to be valid javacript. So maybe custom still gives nicer syntax options
(have to go, thanks for your enthusiasm 🙂 )
> fine, but then why use inline expressions at all and not just use squint normally btw, that would be this argument https://htmx.org/essays/locality-of-behaviour/
my point wasn't to argue for or against locality, but if you're using local snippets, why compile to JS that behaves different, was my question to Martin
> fine, but then why use inline expressions at all and not just use squint normally Mostly to not have a compiler on the client and be able to provide some wrapping constructs for handlers... but maybe that can be achieved in other ways as well 🙂
So maybe just wrapping the ="..." expressions in a (this-as el ...)
would be enough, then the user could write:
(-> el ...)