Query return extended observable directly #27
-
I saw that when you execute useQuery currently it returns an object with a result$ property. Did you think about the possibility to return an observable directly that you extend with some other properties? Like here |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 13 replies
-
I actually start with this approach, but it doesn't work with pipeable operators. For example: // This will break the type
// You will not see the added methods
const projects$ = service.getProjects().pipe(tap()) |
Beta Was this translation helpful? Give feedback.
-
41538f7#diff-1bef14e2637a11619849bb4e431011a04387dcb25bd49abd10f39a286a0609c5L104 |
Beta Was this translation helpful? Give feedback.
-
I remember now I had this problem too 😅. |
Beta Was this translation helpful? Give feedback.
-
I am gonna check a bit today If I found something for the |
Beta Was this translation helpful? Give feedback.
-
My goal was to touch the bare minimum in the source code and provide the best DX we can have. |
Beta Was this translation helpful? Give feedback.
-
I removed the need for unsubscribing explicitly when using the updateQueryKey. |
Beta Was this translation helpful? Give feedback.
-
Exactly what I wanted too and I think it's the best approach. Just a bit sad about the pagination because all the rest is pretty cool and straightforward |
Beta Was this translation helpful? Give feedback.
-
Yes, but it's not that bad for what you get. Moreover, not everyone needs it. |
Beta Was this translation helpful? Give feedback.
-
I had an idea for the pagination and if we pass an observable to |
Beta Was this translation helpful? Give feedback.
-
@anymaniax I have come up with this solution: export class PaginationService {
private useQuery = inject(QueryProvider);
getProjects = inject(PersistedQuery).use((key: ['projects', number]) => {
return this.useQuery(key, ({ queryKey }) => fetchProjects(queryKey[1]), {
staleTime: 5000,
keepPreviousData: true,
});
});
} projects$ = this.page$.pipe(
switchMap((page) => {
return this.projectsService.getProjects(['projects', page]).result$
})
); |
Beta Was this translation helpful? Give feedback.
@anymaniax I have come up with this solution: