imacrayon / alpine-ajax

An Alpine.js plugin for building server-powered frontends.
https://alpine-ajax.js.org
MIT License
651 stars 13 forks source link

Integration with Alpine.js #86

Closed lobre closed 1 month ago

lobre commented 3 months ago

Hey, great project, i like it a lot! Especially the progressive enhancement part of it.

However, there is something that i don't think is clear when reading the website which is:

What is the advantage of Alpine Ajax being an Alpine plugin? Or said differently, what does it bring to Alpine users apart from the attributes that are familiar? Like how does it reconciliate with the state of my local Alpine "components"?

I know there is the morph strategy, but apart from that, how does it reconciliate or integrate with the Alpine js ecosystem (which is about frontend sprinkling for interactivity).

I struggle to understand how my local frontend Alpine js component relate to Alpine Ajax x-targetted ones.

I think it would be interesting to have more guidance and examples on the website that mix regular Alpine js behavior and Alpine Ajax, to clearly understand the role of the server as it brings a whole new dimension to Alpine js.

I don't know if my concern is clear, and sorry if it is not ^^. The Alpine Ajax model is still new to me and I try to grasp the concepts.

imacrayon commented 3 months ago

Hey! Thanks for the thoughtful question.

So when I first started building Alpine AJAX I was already using Alpine in most of my projects. It was - and still is - my favorite way to build UIs. I think it works well as a modern replacement for jQuery and the first-party packages that come with it cover most of the functionality that jQuery provides. The one jQuery feature I noticed that was missing from Alpine was $.ajax so that's where the idea and name for Alpine AJAX came from.

Alpine AJAX originally started as a simple function that would fetch some HTML and insert it into the DOM, since then it's evolved to cover a lot more. Early on I assumed that as Alpine AJAX gained more functionality and became more complex it would take advantage of more of the internal APIs that Alpine provides. This hasn't actually been the case, in fact, the more I use Alpine AJAX the less I've needed to depend on Alpine's core.

So to answer your question, no, I don't think there is a big advantage to Alpine AJAX being an Alpine plugin. I still think Alpine is the best way to built UIs, the DX and packages it provides are awesome, but none of it is a hard requirement for Alpine AJAX to work.

One idea I've been considering for a while now is extracting Alpine AJAX core into a stand alone library under a new name. Alpine AJAX would still exist, it would just be refactored as wrapper around the new AJAX library, in the same way Alpine Focus is a wrapper for Tabbable.

lobre commented 3 months ago

This explanation effectively brings more context. Thank you for detailing all of that.

One idea I've been considering for a while now is extracting Alpine AJAX core into a stand-alone library under a new name. Alpine AJAX would still exist, it would just be refactored as a wrapper around the new AJAX library

That would be awesome for people who don’t especially use Alpine.

I strongly think you are onto something with this hypermedia design that resonates with progressive enhancement. Htmx is great but it already does a lot (too much?), and breaks the rules from the "traditional web". Your approach is more minimalist and friendly with the web platform. Also, you have nice design ideas such as this x-sync, or the HTTP error codes that target different components. This is smart!

c-nv-s commented 1 month ago

I understand the paradigm of this plugin follows that htmx etc for primarily swapping html chunks into the DOM, however is it also possible to perform simple fetch requests and update the x-data model with this plugin as well?

imacrayon commented 1 month ago

@c-nv-s No, sorry, this project is just focused on HTML, but https://github.com/hankhank10/alpine-fetch might be what you are looking for.

c-nv-s commented 1 month ago

ok thanks, but doesn't look like that allows setting Headers or sets the aria-busy attribute like this project. thanks again

imacrayon commented 1 month ago

I'm gonna close this out but feel free to reopen if you have other questions/comments, building out a "standalone" version of Alpine AJAX is still very mush on my radar, but I want to work out a few more APIs before making that jump. I'll share more when there's something to show.