Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L&D experiment on replacing JS with Hyperscript #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

denialanderror
Copy link
Contributor

@denialanderror denialanderror commented Jun 26, 2024

Hyperscript is a JS library developed by the same team as HTMX along the same principles, with "Locality of Behaviour" being key. Rather than having JS in a separate file affecting HTML elsewhere, the intention is to keep the code that affects change in the same location as the elements that need changing.

It does this with a natural language approach. In a lot of ways, it is simpler than much of the JS it is replacing and it is easy to see at a glance what it is doing. Writing it however is harder, as it is effectively a whole new language, which is a barrier to adoption. I was able to replace most of the JS, including for opening and closing the additional details in the Invoices table, but found it hard to work out the syntax to replace the error validation handling.

Another benefit of Hyperscript and Locality of Behaviour is the code is included in the HTML returned from the server. This gets round the issue of needing to place all scripts within the htmx.onLoad function to reestablish event listeners.

In summary, it is an odd language but has some really cool features and potential benefits. While I would be keen to adopt it (because I like odd things - I'd also be keen to write everything in Lisp for example), I'm not necessarily saying we definitely should. Much like HTMX though, it is opt-in, in that it doesn't stop you from using vanilla JS in any way, so it can be used as a progressive enhancement rather than a replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant