Declarative Enhancement for HTML
twinspark.js.org
twinspark.js.org
I am fine with writing a little js has long as it's colocated with the (augmented) html and css. I think the svelte approach scales better and seems more easily debuggable because it enforces a structure and is more readable. There is enough stuff in my html tags already.
Svelte was too js-heavy, and it requires js backend to be rendered on the server - while we had no js engineers. Plus markup was already done, as we rendered it server-side when using React.
But sure I trust you that the htmx way was the way to go for your use case/situation
But your comment forced me to, so I've put something in there, even if it's not really thought through. :)
OTOH that's an interesting thought and it feels like just an addition of one command to whatever there are in actions ( https://twinspark.js.org/api/ts-action/ ) right now... I need to think about it a bit. :)
— Require additional client-side templates and then it's back straight to hell;
— Require really specific JSON structure, basically HTML-in-JSON, which will be ugly as hell and totally meaningless. Meaningless, because then it means I need to adapt my API to this format, and then I can just make it return HTML.
As for the first - it could give a way to use legacy apis and static data. Not sure if I want this in the core, but… how hard can it be?
I am tired of MVC frameworks, SPAs, writing CSS, JS, dealing with tooling, setting up IDEs to format the code properly, etc, I just want to create nice webapps, and want my app designed nicely from the first line of code I write.
Could it perhaps be that you are confusing familiarity with simplicity?
Wait till you get tired of writing html - and you will have caught all the pokemon :-)
In case you didn't spot this part:
> Some reasons why TwinSpark exists despite HTMx and Unpoly (those are similar in approach):
>
> It’s really small (8KB .min.gz).
> There is no attribute inheritance — keeps surprises away.
> Batching - very useful if you want to use HTTP caching effectively, while maintaining some personalisation for your users.
> Bundled - a lot of practical stuff packed in, like actions, or non-traditional event triggers, or morphing.
> Extensibility - you can easily register new directives the same way those in core are registered.
Why do you "need to"? Use what works for you. Glance over new stuff and dig deeper if some aspect of it appeals to you. And if the churn stresses you out then don't.
I think a bigger difference is that TwinSpark seems to have some integrated DOM manipulation, so it's a bit bigger in scope and less opinionated?
HTMX on its own is great as long as you stay within its philosophy of rendering things on the server.
But most UIs I write need - as in it's optimal for UX and performance or out of necessity because it's talking to a third party - at least _some_ parts to be fully client side rendered.
I personally found that combining HTMX with something like lit-html is kind of the sweet spot for a lot of projects assuming full-stack development. These are very small/light libs that cover a ton of ground with minimal surprises and very good performance per default. The _only_ downside is that you don't get isomorphic rendering code but I happily pay that relatively small cost for having such a simple dependency graph.
JSX is fine too. It's gotten a lot a bad rap because of React, but looping and conditions have never bothered me, despite people's complains about them.
The bidirectional case is already difficult where your changes in the generated source should backtranslate into changes in the supplied data.
But now also declaring interactions in the general case? This endeavour must surely fail, as there are so many possible interactions and so little design space without running into either the inner platform effect, where you're just replicating the host programming language (but with bugs), or Greenspun's tenth rule of programming, where you're accidentally building "an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp".
As an aside: I think a sweet spot is providing some UI elements and a framework for composing them, and then having a kind of DSL to low-code-connect them up in the DOM. You can abstract a lot of stuff away from the end user using, you know, code. And then the DSL can be nice for the interactions.
But we all know that interactivity is hard and complex and no way of writing it down, be that imperative, declarative, or whatnot, will take that away.
Edit: Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.
> disagree that HTML has "failed" in almost any sense
The web was born in html, at some point web development skill shifted from it to mostly js. Why do you think that's the case if not html itself failing to accommodate for modern web development requirements?
It's not a joke that html isn't a real programming language. You can only go so far with it and it definitely offers zero help in modeling the problem's domain or any high level thinking process that programming encompasses.
[citation needed]
I mean, it looks like this if you look at HN (the comments, not the code) and similar places, but imo less in the wild.
Loops, conditions, and variables/transclusions are table stakes, and without them pure HTML is just tedious data entry with extra tags.
Markup is for documents, and the "declarative" aspect of it is that it guarantees certain safety conditions (termination, injection safety, maintainability) without sending the author into a full Turing-complete programming environment and everything that goes with it, requiring experience, testing, choice over implementation alternatives, maintenance, debugging, and more laborious/expensive hosting with monitoring, etc. Markup is for ambitious tech-savvy end users/non-developers, and the high end of a non-Turing markup language operating purely at the level of syntactic manipulation, unlike htmx and TwinSpark, IMHO would be SGML, containing a finite state mechanism for context dependent styling or other processing and natural injection-free templating/macro expansion.
Now the web has pushed the limits of what can conceivably be called "documents" eg blogs with threaded comments, table of contents and other navigational idioms, etc. For these kind of "content apps" (supported by SGML still), there has always been a struggle between full Turing complete environments and increasingly idiosyncratic markup techniques.
That struggle is even more noticeable when looking at CSS. IMO, CSS has aggregated such an enormous complexity while most advanced use cases fall straight into "app" territory. That is, there is no justification for most recent CSS features when those features can only realistically be applied in the presence of JavaScript anyway, and thus should actually be implemented using JavaScript rather than bloating CSS. Case in point: the has() selector which doesn't materially enhance what you can do with HTML/CSS but clearly is introduced in support of components and modularity; ie requiring JS anyway, and with JS allowing much better modularity already anyway, is hence just redundant. Clearly, also calc() and custom properties are doubling what's already available.
Both of those examples have an "escape hatch", where you can drop into an imperative API if you need to, so I can see the argument for them not being a perfect abstraction of the underlying primitives, but that doesn't mean they're not useful and a good fit for the problems they're solving.
I had a reference on main page for a long time...