Skip to content

Commit

Permalink
refactor(angular-query) refactored to implicit return
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerGronich committed Dec 8, 2024
1 parent 5da9025 commit 36605e6
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions packages/angular-query-experimental/src/create-base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function createBaseQuery<
const options = runInInjectionContext(injector, () => optionsFn())
const defaultedOptions = queryClient.defaultQueryOptions(options)
defaultedOptions._optimisticResults = isRestoring()
? 'isRestoring'
: 'optimistic'
? 'isRestoring'
: 'optimistic'
return defaultedOptions
})

Expand Down Expand Up @@ -105,27 +105,29 @@ export function createBaseQuery<
effect((onCleanup) => {
// observer.trackResult is not used as this optimization is not needed for Angular
const observer = observerSignal()
const unsubscribe = isRestoring() ? () => undefined : untracked(() => {
return ngZone.runOutsideAngular(() =>
observer.subscribe(
notifyManager.batchCalls((state) => {
ngZone.run(() => {
if (
state.isError &&
!state.isFetching &&
shouldThrowError(observer.options.throwOnError, [
state.error,
observer.getCurrentQuery(),
])
) {
throw state.error
}
resultFromSubscriberSignal.set(state)
})
}),
),
)
})
const unsubscribe = isRestoring()
? () => undefined
: untracked(() =>
ngZone.runOutsideAngular(() =>
observer.subscribe(
notifyManager.batchCalls((state) => {
ngZone.run(() => {
if (
state.isError &&
!state.isFetching &&
shouldThrowError(observer.options.throwOnError, [
state.error,
observer.getCurrentQuery(),
])
) {
throw state.error
}
resultFromSubscriberSignal.set(state)
})
}),
),
),
)
onCleanup(unsubscribe)
})

Expand Down

0 comments on commit 36605e6

Please sign in to comment.