imacrayon / alpine-ajax

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

Programmatically merge elements #88

Open ryands17 opened 4 weeks ago

ryands17 commented 4 weeks ago

I wanted to know if alpine-ajax supports morphing of elements from JS directly i.e. A JS API to do that from a script tag

imacrayon commented 3 weeks ago

Alpine AJAX simply uses Alpine Morph. Alpine Morph is a single function that doesn’t have a dependencies, so you should be able to import it and use it where you need to.

ryands17 commented 3 weeks ago

Does morph support options like Alpine-Ajax does, like appending to an element instead of entirely replacing it?

I would love if alpine-ajax expose the function that does this.

imacrayon commented 3 weeks ago

Ah, sorry, we don't have anything like that at the moment - but I'm looking into refactoring some things and exposing some of those core functions soon! In the meantime you can have a look at the merge method in the code to get an idea how you could build implement something yourself: https://github.com/imacrayon/alpine-ajax/blob/main/src/index.js#L497-L534