Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by benbristow on Tuesday November 23, 2021 @12:57PM
(#29320896)
https://www.django-unicorn.com/examples/count-characters
Sending an AJAX request every time you enter characters just to count them. Ewwww.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by adparadox on Wednesday November 24, 2021 @08:00AM
(#29329551)
Howdy, creator of django-unicorn here. Some of the UI-specific examples are a little contrived and wouldn't be what I consider a really great idea, but it's more to show the possibilities, i.e. instead of counting characters, you could do a heavy ML task to analyze the text.
Personally, I mostly use Unicorn as a component library to split up functionality from the view code, and as a way to persist data to the backend (which would already be an AJAX call) without the hassle of creating an API, dealing with serializers, etc.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by alpha_squared on Tuesday November 23, 2021 @01:01PM
(#29320953)
I guess that's the extreme end of no-js. Wanting to use compute, but philosophically sticking-to-your-guns on where that compute happens.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by benbristow on Tuesday November 23, 2021 @01:10PM
(#29321054)
Well it's still using JS to send the AJAX request, so in-fact something along the lines of 'on text change, set some element text to text.length' is a lot less JavaScript code than 'on text change, format and POST an AJAX request and then set the element text to a value within the response'.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by RussianCow on Tuesday November 23, 2021 @01:17PM
(#29321144)
The difference being that the code to send an Ajax request an update the DOM based on the response is already coded and already used in other places, whereas updating the text length client-side would have to be custom code. Not that I'm arguing one way or another, but the reason it's done that way is to reuse the same set of primitives for everything.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o...
by porker on Tuesday November 23, 2021 @04:08PM
(#29323566)
I've been looking at these libraries and Unpoly looks the most promising for my needs. HTMX looks good as well but Unpoly's infinite layers feature [1] rather grabbed my attention :)
Stimulus is the one I can't get myself to like. Separate JS controllers is clever but the DSL and general nature - it just doesn't click with me.
For my latest project[1], I've opted for https://unpoly.com instead of Alipine+htmx as Unpoly allows me to write 100% server-side code and sprinkle some progressive enhancement where desirable. As a result, I can offer a no-JS experience (minus the Stripe Checkout) for those who may want/need it. Additionally, it forces me to focus solely on the server-side, and I write more idiomatic Django code as a result.
[1]: https://heraldsms.com