by monknomo · 3y ago · 0 comments
I think the button might be something like this, I'm borrowing from their [delete row example](https://htmx.org/examples/delete-row/).
`<button hx-confirm="Really delete {{item.name}}?" hx-target="closest tr" hx-swap="outerHTML swap:1s" hx-delete="<the url>">Delete this car</button>`
In terms of your update example, yeah I think that's what htmx would do, just on the server, and returning rendered html.A simple click is almost never just "delete a row": you need to update the row count in the UI, validate whether it's the last row and therefore can't be deleted, send a log message that pulls data from user state (are you going to construct this state in the API handler every time a row is deleted?), update a heavy graph that shows a visualization of the data in rows, etc...
Maybe some very basic websites can survive with HTMX but that's incredibly not future-proof.
if you had something like a count that was outside that area you could use an event, an out of band swap or just expand the target. we also have morph-based swaps that make it possible to retain more UI state while expanding the target area, if you'd like
if you have some sort of visualization, you'd recompute it server side and stream it back, or use events to trigger an update
adam james has done some cool stuff w/clojure and htmx visualizations:
https://twitter.com/RustyVermeer/status/1701048955105391044
a little bit of hypermedia-friendly scripting can go a long way:
https://htmx.org/essays/hypermedia-friendly-scripting/
you are correct that htmx isn't for every application, but it can likely pull off a lot more than you think, and at much lower complexity levels than reactive options, which has been borne out by real world experience:
https://htmx.org/essays/a-real-world-react-to-htmx-port/
as far as htmx being future-proof, I would point to it's predecessor, intercooler.js, which was released in 2013 and is still actively supported, simply because the code isn't hard to deal with. you could probably figure out and maintain htmx.js in a day or two, as a good JavaScript developer, something that can't be said for most other javascript frameworks.
I think i can like HTMX because its backend agnostic just template it out and return the html. Given 99% of the angular work i do is "get the json, render the returned json to html in angular". I think HTMX can pretty much replace angular with those sort of tasks. That makes being full stack dev quiet easy only need to know my backend stuff, html(x), css(tailwind). Maybe you need some lightweight frontend state framework to do a bit more in the frontend. But its a shitload less to learn than angular, node, typescript, build tools etc etc.
but also, I'm not trying to provide a complete solution, just a direction to look in.