Issue № 13: Shade of the Lime Tree
Blogs Corner
Andrew Meier, Dynamic forms with hyperscript
By ‘dynamic form’ I mean an HTML form where the inputs can change based on how the user populates the form. I tend to need this when there is an array type in the data and the number of elements in the array is specified by the user, or when there is a union type in the data and I want to change the inputs shown based on the case selected by the user. An example is worth a thousand more words.
https://andrewmeier.dev/dynamic-forms-hyperscript
Maarten Balliauw, HTMX for ASP.NET Core Developers – Tutorial
If you’re developing ASP.NET Core applications, and are looking at building a rich client-side experience, you’re in luck. We just published a new tutorial to the JetBrains .NET Guide:
HTMX for ASP.NET Core Developers
In this tutorial, our developer advocate Khalid Abuhakmeh introduces you to HTMX, and how to integrate it into your ASP.NET Core apps.
JetBrains’ support for htmx is still quite surreal. The tutorial is freely available to all:
ASP.NET Core developers predominantly spend their development time on the server, trying their best to steer clear of the scary world of client-side development. But here’s a secret, it doesn’t have to be a daunting prospect to build client-side experiences if you use HTMX. Learn what HTMX is, how to integrate it with your existing knowledge of ASP.NET Core development, and how to take your client-side development to the next level with relative ease. You’ll never look at client-side development the same way ever again.
https://blog.jetbrains.com/dotnet/2022/04/27/htmx-for-asp-net-core-developers-tutorial/
Haskell + htmx + _hyperscript?
Rashad My talk “Hypermedia-Driven Web Apps in Haskell” has been accepted by the Houston Functional Programmers User Group. I’ll be giving the talk in September. This talk will be great for not only Haskell users, but any web developer who would like to integrate htmx + more data-driven development or functional programming ideas into their web application code.
The star of my presentation is “Function Based Views” (Django jargon […]) and why it works very nicely with htmx. A web app designed in this manner is basically a composition of simple functions with the type :toHypermedia : SomeDataType -> Hypermedia
🎊 5 👑 3
Rashad Gover, Hypermedia-Driven Web Apps in Haskell
In this talk I present a new approach to building web apps in Haskell, using htmx. htmx gives you access to AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext. With the power of this technology, Haskellers can now build 100% Haskell web apps without depending on GHCJS. I’ll also be briefly showcasing a new microframework based on monadic parsing called Okapi. Okapi was inspired by F#’s Giraffe, and is meant to be a lightweight, simple tool used for rapid prototyping and learning server-side web development.
The talk will be held online on .
Best of luck to Rashad on the talk! 💙💙💙
https://hfpug.org/event/rashad-gover-hypermedia-driven-web-apps-in-haskell/
Our own Rashad and Anthony have been working on some very cool things:
Rashad Wait until you see the hyperscript quasiquoter in the works…Haskell will be able to verify the syntactic validity of your hyperscripts…At compile time (the best time)!
<button
class="text-lg bg-blue-500"
_="on click increment :x
if :x <= 3
put :x into the next <output/>
else
put '3 is the max...' into the next <output/>
end"
>Click Me</button>
<output>--</output>becomes
myButton = do
button_
[ class_ "text-lg bg-blue-500"
-- Below is a quasiquotation in Haskell. Parsed at compile time,
-- so we can check for syntax errors.
, [__|
on click increment :x
if :x <= 3
put :x into the next <output/>
else
put '3 is the max...' into the next <output/>
end
|]
]
"Click Me"
output_ [] "--"
_hyperscript for Sublime Text coming soon
gnat has been contributing to the _hyperscript grammar that powers the VSCode plugin, and has undertook a Sublime Text plugin based on the same grammar.
The plugin is now awaiting approval – a rather involved process.
Thanks to gnat for these contributions! 💙
https://github.com/wbond/package_control_channel/pull/8517
The _hyperscript code organization debate
Some doubletexts have been merged
1cg i think we should go back to one file man
1cg one big ol javascript file. maximum contrarian. lets do it. c’mon
Deniz Akşimşek but scrolling is so tiring
1cg tab switching is worse! one, single, glorious, insane file, it speaks to me
…
Deniz Akşimşek ok. compromise: we will make each plugin be one module
…
Deniz Akşimşek what is our goal for browser support btw?
1cg hyperscript or htmx?
Deniz Akşimşek hyperscript
1cg modern browsers – all browsers - IE
Deniz Akşimşek how modern, can we depend on import
1cg we can talk beyond that
1cg caniuse: [Image: Can I use modules?] not awful
1cg y tho when we can have one big file 🤌
Deniz Akşimşek
<script type="module">
import _hyperscript from "https://esm.sh/hyperscript.org"
import eventsource "https://esm.sh/hyperscript.org/eventsource"
_hyperscript.use(eventsource)
</script>1cg I guess I can live with that
Deniz Akşimşek if we can depend on ES modules i can finally fix workers
1cg 😑 I’m willing to take a look at it.
1cg how did I get from “one file” to “es modules” in ~5min? 😑
Deniz Akşimşek es modules are the simplest
1cg … next to…
Deniz Akşimşek making sure the right global variable is there sucks. ordering script tags correctly sucks.
(function() { ... })()
what the fuck is this1cg 100% agreement there
Seems pretty positive so far, right? But there are some caveats…
gnat es modules bring their own layer of complexity and barrier to entry tbh.
one file + no build step = anyone can jump in and get context without setting up a build system. less moving parts.
The cost of removing simplicity is always difficult to forsee the consequences of because were all so ready to use the new shiny…gnat Carson has been around long enough to see so much tech come and go… he’s super well in-tune for keeping it anti-hype, anti-layer.
Its this exact reason so many of us love htmx and hyperscript.
Its why they will stand the test of time.Deniz Akşimşek Explain how es modules add complexity over something like UMD
gnat sadly es modules require a server environment because of CORS.
(function() { ... })()
just works man, even from plain .html files directly off your drive.
that’s a big advantage: A new dev from the orange site can download hyperwordle.html and actually tinker with it.
playing with real hyperscript is IMHO the quickest way to make a new user-- Getting to that point needs to be friction free: the language is already different enough!
It’ll be detrimental to the growth of the language for new users to get hung up on CORS shit.gnat That said, didn’t mean to come off as harsh, you’re an amazing contributor dude.
Deniz Akşimşek i guess the real problem is that the hyperscript codebase is aging and i’m just trying to compensate
I hadn’t even thought of this, since I never try to view local HTML files without a server. That’s why participating in the development of things you use is important! 🐝
The _hyperscript codebase has grown quite quickly, and to simplify it, we need your feedback:
- Would you be fine with needing a dev server to run a file? (i.e.:
python3 -m http.server
) - Do you need to support browsers that lack ES Modules?
How to test HTML templates
h*ckraiser666 fairly new to both go and htmx; do you guys unit test your html template files? coming from stuff like react, unit testing your components is par for the course. wondering if there are some strategies for server side templates too
TardisX I do 🙂 With the proper abstractions it’s quite easy. I am doing simple regex based checks of content output, but you could use something like goquery if you needed to do DOM traversal style stuff as well.
3Dayo I tend to use goquery far more in my tests than regex
h*ckraiser666 oh interesting. I’ll check that out
benpate Ashamed to say “no” I don’t really unit test my templates. At some point, front-end testing gets hard because presentation is so subjective.
But, I’m thinking I probably could (ok, should) make some tests where I pass in different values and guarantee that the templates don’t error out.benpate Goquery is awesome and underused 🙂
Deniz Akşimşek microformats are the answer to everything.
Deniz Akşimşek put your html through a microformats parser then test the output data
Deniz Akşimşek i don’t think you can test a template in isolation, you need to test the endpoint that renders it
benpate Ok, who does this college kid think he is, and why are his answers always correct?
benpate I have been working microformats into my latest templates. They are spiritually similar to htmx – walking the full circle from computer-readable HTML -> human-readable HTML -> then back again to computer-readable.
Deniz Akşimşek there’s something very philosophically pleasing about humans and API clients using the same source of truth
This story is very important and definitely not a front for me to promote microformats.
Use the 204 No Content status code to optimize polling
A user had a table being polled every 2 seconds. The table was being augmented with a JavaScript library, which caused jitter every time the server was polled — regardless of whether the table changed.
Deniz Akşimşek compute some sort of hash for the data in the table and put it in an
<input type="hidden">
, include that hash in the request with hx-include, on the server if the data hasn’t changed return 204 No Content
You can use the 204 No Content status code to tell browsers they should keep showing the old page, and htmx respects this convention by not swapping.
There is actually a bit of a debate about whether htmx should swap 204 responses. I hold that if you need anything visible to happen upon the response being received, 204 is the wrong status code to use — use 200 OK with an empty body instead.