query icon indicating copy to clipboard operation
query copied to clipboard

Add example of lit query adapter

Open Gabswim opened this issue 1 year ago • 5 comments

This is just a draft PR to follow up on the discussion I started a while ago here: https://github.com/TanStack/query/discussions/6390

Gabswim avatar Jul 11 '24 04:07 Gabswim

Hello! Thanks a lot for attempting to bridge Lit and Tanstack Query.

I tried to make this works locally, just to see.

Small, ongoing PR for fixing build, adding a mutation controller, example(s)…: https://github.com/Gabswim/query/pull/1

EDIT ~~And some whitespace tests issues~~ (never mind, it was just prettier)

JulianCataldo avatar Sep 14 '24 14:09 JulianCataldo

Hello! Thanks a lot for attempting to bridge Lit and Tanstack Query.

I tried to make this works locally, just to see.

Small, ongoing PR for fixing build, adding a mutation controller, example(s)…: Gabswim#1

@JulianCataldo Nice to have you onboard! I've made some additions with a context provider also. https://github.com/Gabswim/query/pull/2 Feel free to try it out.

klasjersevi avatar Sep 23 '24 07:09 klasjersevi

Context provider is a huge addition. I'll try this as soon as I can :) IDK if @Gabswim viewed my PR, I wish to go on helping while avoiding duplicating efforts ^^. I can add more examples, WDYT? And try to do achieve tests for MutationController, also. Tell me, and I'll try to help with the best I can achieve.

Ty!

JulianCataldo avatar Sep 24 '24 13:09 JulianCataldo

Thank you for your contributions @JulianCataldo ! I saw your PR, but I’ve been more focused on the one for the context provider by @klasjersevi .

Before going any further, I think it would be good to get some feedback from @TkDodo, justinfagnani, just to make sure we're all aligned.

One challenge, which I believe has no workaround with Lit’s context, is its asynchronous flow. This issue doesn't seem to exist in other packages, as seen in these implementations:

Svelte: getContext SolidJS: useContext

Gabswim avatar Sep 25 '24 03:09 Gabswim

One challenge, which I believe has no workaround with Lit’s context, is its asynchronous flow. This issue doesn't seem to exist in other packages, as seen in these implementations:

Svelte: getContext SolidJS: useContext

Just to explain for anyone who is not familiar with Lit Context:

Lit context is an event-based protocol between web components based on the Context Community Protocol by the W3C's Web Components Community Group. Normally this happens synchronously as long as the context provider (parent node) is defined before the context consumer is defined. In some cases this can happen in a different order or if the provider is not yet available for any reason. So the context might be available directly or it might be available at a later point. To overcome some of the challenges with this lit also provides a ContextRoot that can take care of requests until the context provider is available.

Many other context api:s in other frameworks are synchronous, which instead throws errors instantly if a context isn't available directly.

klasjersevi avatar Sep 25 '24 07:09 klasjersevi

any progress?

JosefJezek avatar Dec 11 '24 11:12 JosefJezek

I think we had some good progress with an initial example that should be quite usable. I will soon try to replace some of our custom (very similar) Lit Query controllers with these and see how it works out. It would be great if more people could try these out, so we would know how to proceed moving this forward.

klasjersevi avatar Dec 11 '24 11:12 klasjersevi

@Gabswim thanks for your all effort on this. I did not get why such a great server state manager still do not have litElement adapter event it is almost done.

erhanfirat avatar Jan 24 '25 19:01 erhanfirat

Will this update pushed to the main library? I'd like to know when can I use it because I'd like to use tanstack query on lit-element project now...

KirschX avatar Apr 14 '25 06:04 KirschX

sorry I didn’t really look at this because it was a draft PR. I can’t comment much on the lit specific code, but what we would want for an adapter that lives in our monorepo is mainly to have a maintainer who is consistently willing to work on the adapter and who is available for questions on discord.

our adapters need to be well maintained because if we make changes to the core that require adapter changes, I need to rely on adapter maintainers to help out.

So, if someone wants to step up and take this to the finish line AND is willing to maintain it in a long run, please reach out to me on Discord.

Also please note that we have to get the APIs right, because once an adapter is released, it has to stay on the current major version (5) - we can (right now) only bump the major for all adapters. We will likely not make a major version bump for all adapters because the lit adapter needs some tweaks 😅 . That’s also why the angular adapter is still marked as experimental.

I will close this PR for now because the package structure & setup has changed in the meantime and I think it’s easier to just start from scratch, but this doesn’t mean that a lit adapter won’t make it.

TkDodo avatar Apr 14 '25 07:04 TkDodo