4 ms·
Hey everyone I’m the creator of hyperscript (and htmx). I know the syntax for hyperscript is a bit jarring but it is designed to embed well directly in HTML for
by recursivedoubts 3y ago
Hey everyone I’m the creator of hyperscript (and htmx). I know the syntax for hyperscript is a bit jarring but it is designed to embed well directly in HTML for light scripting needs, as a complement to htmx. It isn’t designed to be a language for building a ton of logic in.
It is easier to read rather than to write by design and is inspired by HyperTalk, the scripting language for HyperCard. I don’t expect or recommend it to be a general replacement for JavaScript, but it can be nice for light scripting for the web.
As far as features go, besides the xtalk based syntax it has things like CSS literals and relative positional expressions that make scripting the DOM easier:
on click toggle .active on the next <div/>
probably the most interesting feature to most HN is that the runtime automatically resolves promises so script writers don’t have to:
https://hyperscript.org/docs/#async https://hyperscript.org/docs/#async
this, coupled with event-based control flow can make for some interesting scripting patterns.
Anyway, not for everyone but it is a passion project of mine and is being used in production. I’m hoping to get it to 1.0 this summer after htmx 2 stabilizes. Happy to answer questions.
- recursivedoubts 3y agoOh, one other interesting thing about hyperscript is that it is a pluggable parser so you can add new language features to it if you want. Kinda neat.
- eyelidlessness 3y agoThat’s definitely a neat idea. Is it modeled after any specific language customization approach? Is it well positioned for, say, macros?
- recursivedoubts 3y agoI know tcl also allows you to extend the language, but i have to admit I've never looked too much into it. Like tcl, hyperscript has strong start tokens for most statement-like things (we call them commands, as does tcl if i understand correctly). I don't think it maps well to macros, it's just an open parser that you can plug new stuff into pretty easily by adding a keyword + some parsing and eval logic to dynamically.
- eyelidlessness 3y agoEven though you’ve explicitly positioned it for light scripting, do you have concerns about de-“color”ing async (as in obscuring the fact that it’s infectious) as a potential footgun?
- recursivedoubts 3y agoit can get you into trouble if you really want async behavior but promises are resolved at the expression level by the runtime (slow) so it's hard for them to leak out and, for scripting, it is usually a nicer experience: on click fetch /foo then put the result into me
- err4nt 3y agoMay I ask: if it's intended to be used with HTML language, why not use legal HTML syntax? (Custom author-defined tag names, custom attributes for those custom tags, and data-* attributes on any element are all legal ways to extend HTML with new attributes)
- recursivedoubts 3y agoyou can use a data attribute if you want, data-script="on click log 'yay'" i don't have strong opinions on that, i've been told by people who work on the browsers that, from a practical perspective, custom non-data attributes are supported and always will be, and the underscore attribute is a tribute to underscore.js, a library I always liked.
- err4nt 3y agoSome thoughts: Browser developers today can't speak for the way browser makers in the future may build standards-based browsers. Standards provide a level of future-proofing. Also browsers are not the only tools developers will use to interact with HTML. And most importantly, the custom extensibility built-in to the HTML language is supported by all browsers as well.
- recursivedoubts 3y agoyep i get it, you can use data attributes if you want, but i've been told by high ups on both the chrome team and the edge team that it doesn't matter i am not ideological about it