Skip to content
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

feat(signals): Add refetch functionality to intersected results #163

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions query/src/lib/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export function intersectResults$<
return map((values) => {
const isArray = Array.isArray(values);
NetanelBasal marked this conversation as resolved.
Show resolved Hide resolved
const toArray = isArray ? values : Object.values(values);
const refetch = () => Promise.all(toArray.map(v => v.refetch()));

const mappedResult = {
all: values,
Expand All @@ -158,6 +159,7 @@ export function intersectResults$<
isFetching: toArray.some((v) => v.isFetching),
error: toArray.find((v) => v.isError)?.error,
data: undefined,
refetch,
} as unknown as QueryObserverResult<R> & { all: T };

if (mappedResult.isSuccess) {
Expand Down
8 changes: 5 additions & 3 deletions query/src/lib/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export function intersectResults<
signals: T,
mapFn: (values: UnifiedTypes<T>) => R,
): Signal<QueryObserverResult<R> & { all: T }> {
return computed(() => {
const isArray = Array.isArray(signals);
const toArray = isArray ? signals : Object.values(signals);
const isArray = Array.isArray(signals);
const toArray = isArray ? signals : Object.values(signals);
const refetch = () => Promise.all(toArray.map(v => v().refetch()));

return computed(() => {
const mappedResult = {
all: signals,
isSuccess: toArray.every((v) => v().isSuccess),
Expand All @@ -72,6 +73,7 @@ export function intersectResults<
isFetching: toArray.some((v) => v().isFetching),
error: toArray.find((v) => v().isError)?.error,
data: undefined,
refetch,
} as unknown as QueryObserverResult<R> & { all: T };

if (mappedResult.isSuccess) {
Expand Down
Loading