-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Children, teleport and fx ideas #5
Comments
Interesting. I think the teleport should just be handled by the To support children we probably only need to make the if (selector.tagName == 'BODY') return el.replaceChildren(...selector.children); into if (selector.tagName == 'BODY' || modifiers.includes('children')) return el.replaceChildren(...selector.children); for getting all children children of an all selector modifiers.includes('all') ? doc.body.querySelectorAll(query) : doc.body.querySelector(query)
// to
modifiers.includes('all') ? doc.body.querySelectorAll( modifiers.includes('children') ? query+'>*' : query) : doc.body.querySelector(query) That should handle those cases. Want to test it and make that PR? |
Nice one, thanks. I will check that out soon and see if I can make sense of it and let you know. I've been experimenting with x-ajax to do some 'load more/infinite scroll and carousel' components from php generated 'paginated pages' from the cms.X ajax in the content lazily for each page into a component and then loop over it using x-for to do stuff. Didn't think it would work so well, but it's quite smooth so far. |
That's good to hear! I have not though about actually using this one in production like I have the others. But this does give me some ideas... 🤔 |
Yeh I love it. Lots of different problems it can solve with few lines and it makes life easy (or at least more interesting). I'm using wordpress (which I hate) so finding ways not to use wordpress while still using wordpress is apparently my mission... For example using it with query strings on the server side means I can grab different templates depending on the context where I'm calling from, but keep the templates in one place. Like if you have some latest posts that you want to show on the home page with a special look and feel, you just make the home page article template on your blog page accessible with a query condition 'context=home'. All the data is on the blog page already so that's easy to build a lot of variations with the same data. Or something like a 'minacart'. Build the mini cart on the cart page behind a query string condition, then when you want to get the mini cart or refresh it you can just call it with x-ajax. And it's easy to refresh it with events. It's also good for data as well. I made a command palette style search with the load more/infinite scroll component. Fetch all the posts lazily, query select and extract text content and build an array of data from the content to search/filter. I think I'm abusing it a quite a bit, but it makes things simple and is a single solution for a lot of different things. |
Hi Erik, I tried to submit some changes, but not sure they ever went through. In any case, it needed some more work and effort try to cover all the cases. This is what I have if you'd like to check it out and seems to be doing the trick, though required a bit more code. There is a test file which should help to illustrate things. Just note the directive is named ajax-mod to run alongside the original for testing purposes. Src: |
Hi Eric, other day I found a need for children and saw it was in your todo. I took a stab at it and also added some other bits (teleport and transitions). In the end I bailed on it as it was easier to just handle things in vanilla, so forgive the mess, but worked ok. Thought I'd leave it here in case there are some ideas for you. Hope you're well
`/**
*/
const xParser = new DOMParser();
export default function (Alpine) {
Alpine.directive('ajax', async (el, { expression, modifiers }, { effect, evaluateLater }) => {
const target = evaluateLater(expression);
let query;
}
const eventDefaults = {
bubbles: false
};`
The text was updated successfully, but these errors were encountered: