We saw my wife’s parents for the first time in 15months this week. It was really great. Somewhat surreal.
At the same time, we’re busy hiding from the masses as the next wave builds. I see many people not wearing masks. I do wonder about that.
Anyhow…
Digging deeper into Alpine.js. I'm still having a lot of fun. There’s a sweet-spot very close to what Alpine offers for the 80% case.
A couple of thoughts:
x-for
make sure to provide the :key
argument. I won’t go into exactly why I bother mentioning that but, providing it avoids much head-scratching. 🥳Alpine’s Reactivity is super. You update the component x-data
, and it handles the re-render automatically for you. This works for nested structures to at least a moderate level of complexity — maybe beyond, but I can’t say for sure.
This Reactivity is reminiscent of the kind of unidirectional data flow made popular by The Elm Architecture, and others since. It simplifies state handling: you update the data store and the UI is handled automatically, against having to go through each part of your UI making sure that was correctly updated too.
The interesting topic, for me here, is how far to push Alpine before it makes sense to make the jump to something more fully featured, which for me would be Elm.
There’s certainly a Full Components approach that’s explicitly out-of-scope for Alpine. I’ve found it to work well enough for a moderately complex tree-like data structure. That, though, was on the cusp. Complex data structure operations are going to be much nicer in Elm’s functional approach, vs raw JS. There won’t be doubts about whether this is too complex or not. Nonetheless, I’ve been pleased that Alpine has gone with me everywhere I’ve tried to push it so far, with very little code for that too.
I'm still learning.