Skip to content

Commit

Permalink
refactor(query): 💡 add sync mutate function and set requireSync
Browse files Browse the repository at this point in the history
... to `true` on `toSignal`
  • Loading branch information
luii committed Nov 7, 2023
1 parent aa6f7fa commit 6b7c57d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions query/src/lib/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type MutationResult<
TVariables = void,
TContext = unknown
> = {
mutate: MutationObserver<TData, TError, TVariables, TContext>['mutate'];
mutate: (variables: TVariables) => void;
mutateAsync: MutationObserver<TData, TError, TVariables, TContext>['mutate'];
reset: MutationObserver<TData, TError, TVariables, TContext>['reset'];
setOptions: MutationObserver<
TData,
Expand All @@ -39,7 +40,9 @@ type MutationResult<
result$: Observable<
MutationObserverResult<TData, TError, TVariables, TContext>
>;
toSignal: () => Signal<MutationObserverResult<TData, TError, TVariables, TContext> | undefined>
toSignal: () => Signal<
MutationObserverResult<TData, TError, TVariables, TContext>
>;
};

@Injectable({ providedIn: 'root' })
Expand Down Expand Up @@ -90,12 +93,17 @@ class Mutation {
})
);

const mutate = (variables: TVariables) => {
mutationObserver.mutate(variables).catch(() => {});
};

return {
mutate: mutationObserver.mutate.bind(mutationObserver),
mutate,
mutateAsync: mutationObserver.mutate.bind(mutationObserver),
reset: mutationObserver.reset.bind(mutationObserver),
setOptions: mutationObserver.setOptions.bind(mutationObserver),
result$,
toSignal: () => toSignal(result$),
toSignal: () => toSignal(result$, { requireSync: true }),
};
}
}
Expand Down

0 comments on commit 6b7c57d

Please sign in to comment.