Replies: 19 comments 58 replies
-
Edit: changed it from
|
Beta Was this translation helpful? Give feedback.
-
Looks super cool, Is is something that can leverage https://github.com/ngneat/query by @NetanelBasal? |
Beta Was this translation helpful? Give feedback.
-
@arnoud-dv awesome amount of work! Definitely the amount of parenthesis might discourage people from trying that out, so 👍 for Question 1: Not sure if core tanstack/query is capable of supporting streams. Hardly anybody in angular area is using Question 2: would providing an example basing on NgModules-based components require extra-effort? Such example might attract more people who didn't move to standalone yet. Again, awesome work, IMO the community needs such port very much. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
I thought this code from your sandbox was nifty. I frequently have a use case where i need to wait for some data (id, form, etc) before creating the query. it would be nice if you could somehow create a dummy query until you have what you need to make the request.
I don't think this code made it into the current release. I'm not sure what the purpose of
i tried to do something like this but it did not seem to work.
|
Beta Was this translation helpful? Give feedback.
-
I really love how simple this is to use. It would probably be useful to see an example that exists in a service as most Angular devs are going to be using that as a simple way to manage things like API calls and global state in their applications. Any updates on when stable is going to be released? |
Beta Was this translation helpful? Give feedback.
-
Example: query = injectQuery(() => ({
enabled: false,
queryKey: ["test"],
queryFn: () => 1,
}))
query.refetch() // Does not make sense, it's just a fetch, not a refetch. "Improved version": query = injectQuery(() => ({
enabled: false,
queryKey: ["test"],
queryFn: () => 1,
}))
query.fetch() // Makes more sense. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
What exactly is the different between this and ngneat/query? |
Beta Was this translation helpful? Give feedback.
-
I'm a developer shifting to angular from react world. It'll genuinely be a great time saver handling out data-fetching responsibilities to query. I checked the code examples in the documentation, seems interfaces are same as react-query. I'll definitely adopt it in real projects as soon as it comes out of the experimental stage! |
Beta Was this translation helpful? Give feedback.
-
Am trying AQ out now and really enjoying the reduction in boilerplate from NgRx (a library I love very much). This is great work! 🙏 |
Beta Was this translation helpful? Give feedback.
-
This looks pretty great, and has been experimental for a while now. With no non-chore, non-release commits in about a month, it seems stable enough to release to me. Is there anything keeping the library experimental besides inertia? I'd love to know what blockers exist to marking it as "ready to use in production." |
Beta Was this translation helpful? Give feedback.
-
I’m interested as well. We’ve used Angular Query for an experimental production app some months ago and it was “ready” (except for something like signal required input etc which was released in that time). I would like to introduce it in our bigger projects, but as it's experimental I'm not 100% sure |
Beta Was this translation helpful? Give feedback.
-
I have been using Angular query in medium sized projects for two months now and I am really enjoying it, especially that it is working with signals as opposed to observables. I am coming from a React background (including react query) and missed the ease of data fetching and handling that this library enables. My only major struggle so far is the typing of Even without a official plugin, persisting the cache with session storage using |
Beta Was this translation helpful? Give feedback.
-
@arnoud-dv is there anything published on the timeline and what's remaining to upgrade I'd like to avoid scrutiny from using something called "experimental" in production deployments. |
Beta Was this translation helpful? Give feedback.
-
Great work with the adapter!! I love how it works seamlessly with signals. As for the feedback:
click to see the example codeimport {Component, inject,} from '@angular/core'
import {injectQuery,} from '@tanstack/angular-query-experimental'
import {debounceTime, fromEvent, lastValueFrom, Subject, switchMap, takeUntil} from 'rxjs'
import {HttpClient} from "@angular/common/http";
@Component({
selector: 'address',
standalone: true,
template: `<input (input)="setInputValue($event)">`,
})
export class AddressComponent {
subject: Subject<string> = new Subject()
setInputValue($event: any) {
this.subject.next($event.target.value);
}
#http = inject(HttpClient)
addressQuery = injectQuery(() => ({
queryKey: ['address'], // <--- I want to add the search value here
queryFn: ({signal}) => {
return lastValueFrom(
this.subject.pipe(
debounceTime(250),
switchMap((value) => {
return this.#http
.get<any[]>(`https://some-url-that.returns/addresses`, {params: {search: value}})
.pipe(takeUntil(fromEvent(signal, 'abort')))
}),
)
)
},
}))
} |
Beta Was this translation helpful? Give feedback.
-
It's amazing! But SSR not being officially implemented is kind of a pain point. Posting a solution (this is for an @NgModule based app):
providers: [
{
provide: BEFORE_APP_SERIALIZED,
useFactory: (doc: Document) => {
return () => {
const script = doc.createElement('script');
script.innerText = `window.__QUERY_STATE__ = ${JSON.stringify(dehydrate(queryClient))}`;
doc.head.appendChild(script);
};
},
deps: [DOCUMENT],
multi: true,
},
], Imports are: import { BEFORE_APP_SERIALIZED } from '@angular/platform-server';
import { queryClient } from './app.module';
import { dehydrate } from '@tanstack/angular-query-experimental';
import { DOCUMENT } from '@angular/common';
export const queryClient = new QueryClient();
// ...
@NgModule({
// ...
providers: [
// ...
provideAngularQuery(queryClient)
],
// ...
})
export class AppModule {}
import { queryClient } from './app/app.module'
import { hydrate } from '@tanstack/angular-query-experimental';
// @ts-ignore
if (window.__QUERY_STATE__) {
// @ts-ignore
const state: any & {} = window.__QUERY_STATE__;
hydrate(queryClient, state);
console.log('hydrated QueryClient successfully', state);
} Also, why was hiding the actual injection token necessary? You could just define QueryClient.ɵprov = ɵɵdefineInjectable({
token: QueryClient,
providedIn: 'root',
factory: () => new QueryClient(),
}) |
Beta Was this translation helpful? Give feedback.
-
I've been trying to use this, just experimentally to learn, and I feel a typical use case is slightly less ergonomical/simple than I had hoped. It works, but I was hoping I could simplify it further. The situation is:
Number 3 means I will likely bind the id into the component either using I have found something that works, but is slightly less ergonomical/simple than I'd like. The query creation looks like this: export class SomeQueries {
static someQuery(someId: Signal<string | undefined>) { // I'd like to avoid "| undefined"
const backendService = inject(BackendService); // some code-generated service for calling the backend
return injectQuery(() => ({
queryKey: ['someQuery', someId()],
queryFn: () => lastValueFrom(backendService.getSomeResource(someId()!)), // I'd like to avoid the !
enabled: () => someId() !== undefined, // I'd like to avoid this check, if possible
}));
}
} And usage: @Component({...})
export class SomeComponent {
someId = input<string>();
someQuery = SomeQueries.someQuery(this.someId);
} Is this the recommended way of handling this case? |
Beta Was this translation helpful? Give feedback.
-
why does no one give production examples of use. since examples are described in the documentation, they are written only on the fence. In the real world, I do not want to take a tool and use it in components, make several levels of abstraction and see if your tool is good, if it integrates well into the framework. make at least an example of todoApiService, todoQueryService, todoService, |
Beta Was this translation helpful? Give feedback.
-
👋 Hi everyone,
I've been working on a pull request for adding an Angular adapter to TanStack Query, and it's now approaching completion.
To give you a better idea of its functionality, here are two sandboxes:
These sandboxes are interactive, allowing you to edit the code and see how it works in your own forked sandbox.
The adapter exclusively uses Angular signals, but integrating it with RxJS is quite straightforward thanks to the Angular RxJS interop. With Tanstack / Angular Query, you can potentially replace most, if not all, RxJS-based server-side state synchronization code. That said, I believe RxJS still has significant applications in modern Angular apps, even after the introduction of signals in the framework. For instance, signals derived from an RxJS stream can be easily integrated into query options for reactive behavior.
For the time being, I'm naming the adapter "experimental." This is primarily to allow for the possibility of making breaking API changes in the future. However, I am quite satisfied with its API, especially with
createQuery
.I'm looking forward to read your thoughts and feedback! If you have suggestions for API changes or any other improvements, now is the perfect time to share them.
Beta Was this translation helpful? Give feedback.
All reactions