Skip to content

Commit 8cbf2a1

Browse files
committed
skipPollOnFocused lost to skipPollingIfUnfocused and yarn format
1 parent 4ae5a9b commit 8cbf2a1

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

packages/toolkit/src/query/core/apiState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export type SubscriptionOptions = {
9090
*
9191
* Note: requires [`setupListeners`](./setupListeners) to have been called.
9292
*/
93-
skipPollOnFocusLost?: boolean
93+
skipPollingIfUnfocused?: boolean
9494
/**
9595
* Defaults to `false`. This setting allows you to control whether RTK Query will try to refetch all subscribed queries after regaining a network connection.
9696
*

packages/toolkit/src/query/core/buildMiddleware/polling.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
6060
if (!querySubState || querySubState.status === QueryStatus.uninitialized)
6161
return
6262

63-
const { lowestPollingInterval, skipPollOnFocusLost } =
63+
const { lowestPollingInterval, skipPollingIfUnfocused } =
6464
findLowestPollingInterval(subscriptions)
6565
if (!Number.isFinite(lowestPollingInterval)) return
6666

@@ -77,7 +77,7 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
7777
nextPollTimestamp,
7878
pollingInterval: lowestPollingInterval,
7979
timeout: setTimeout(() => {
80-
if (state.config.focused || !skipPollOnFocusLost) {
80+
if (state.config.focused || !skipPollingIfUnfocused) {
8181
api.dispatch(refetchQuery(querySubState, queryCacheKey))
8282
}
8383
startNextPoll({ queryCacheKey }, api)
@@ -127,22 +127,22 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
127127
}
128128

129129
function findLowestPollingInterval(subscribers: Subscribers = {}) {
130-
let skipPollOnFocusLost: boolean | undefined = false
130+
let skipPollingIfUnfocused: boolean | undefined = false
131131
let lowestPollingInterval = Number.POSITIVE_INFINITY
132132
for (let key in subscribers) {
133133
if (!!subscribers[key].pollingInterval) {
134134
lowestPollingInterval = Math.min(
135135
subscribers[key].pollingInterval!,
136136
lowestPollingInterval
137137
)
138-
skipPollOnFocusLost =
139-
subscribers[key].skipPollOnFocusLost || skipPollOnFocusLost
138+
skipPollingIfUnfocused =
139+
subscribers[key].skipPollingIfUnfocused || skipPollingIfUnfocused
140140
}
141141
}
142142

143143
return {
144144
lowestPollingInterval,
145-
skipPollOnFocusLost,
145+
skipPollingIfUnfocused,
146146
}
147147
}
148148

packages/toolkit/src/query/react/buildHooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
672672
refetchOnMountOrArgChange,
673673
skip = false,
674674
pollingInterval = 0,
675-
skipPollOnFocusLost = false,
675+
skipPollingIfUnfocused = false,
676676
} = {}
677677
) => {
678678
const { initiate } = api.endpoints[name] as ApiEndpointQuery<
@@ -716,7 +716,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
716716
refetchOnReconnect,
717717
refetchOnFocus,
718718
pollingInterval,
719-
skipPollOnFocusLost,
719+
skipPollingIfUnfocused,
720720
})
721721

722722
const lastRenderHadSubscription = useRef(false)
@@ -817,7 +817,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
817817
refetchOnReconnect,
818818
refetchOnFocus,
819819
pollingInterval = 0,
820-
skipPollOnFocusLost = false,
820+
skipPollingIfUnfocused = false,
821821
} = {}) => {
822822
const { initiate } = api.endpoints[name] as ApiEndpointQuery<
823823
QueryDefinition<any, any, any, any, any>,
@@ -832,7 +832,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
832832
refetchOnReconnect,
833833
refetchOnFocus,
834834
pollingInterval,
835-
skipPollOnFocusLost,
835+
skipPollingIfUnfocused,
836836
})
837837

838838
usePossiblyImmediateEffect(() => {

packages/toolkit/src/query/tests/polling.test.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ describe('polling tests', () => {
123123
expect(mockBaseQuery.mock.calls.length).toBeGreaterThanOrEqual(2)
124124
})
125125

126-
it('respects skipPollOnFocusLost', async () => {
126+
it('respects skipPollingIfUnfocused', async () => {
127127
mockBaseQuery.mockClear()
128128
storeRef.store.dispatch(
129129
getPosts.initiate(2, {
130-
subscriptionOptions: { pollingInterval: 10, skipPollOnFocusLost: true },
130+
subscriptionOptions: {
131+
pollingInterval: 10,
132+
skipPollingIfUnfocused: true,
133+
},
131134
subscribe: true,
132135
})
133136
)
@@ -140,7 +143,7 @@ describe('polling tests', () => {
140143
getPosts.initiate(2, {
141144
subscriptionOptions: {
142145
pollingInterval: 10,
143-
skipPollOnFocusLost: false,
146+
skipPollingIfUnfocused: false,
144147
},
145148
subscribe: true,
146149
})
@@ -157,12 +160,12 @@ describe('polling tests', () => {
157160
storeRef.store.dispatch(api.util.resetApiState())
158161
})
159162

160-
it('respects skipPollOnFocusLost if at least one subscription has it', async () => {
163+
it('respects skipPollingIfUnfocused if at least one subscription has it', async () => {
161164
storeRef.store.dispatch(
162165
getPosts.initiate(3, {
163166
subscriptionOptions: {
164167
pollingInterval: 10,
165-
skipPollOnFocusLost: false,
168+
skipPollingIfUnfocused: false,
166169
},
167170
subscribe: true,
168171
})
@@ -173,7 +176,10 @@ describe('polling tests', () => {
173176

174177
storeRef.store.dispatch(
175178
getPosts.initiate(3, {
176-
subscriptionOptions: { pollingInterval: 15, skipPollOnFocusLost: true },
179+
subscriptionOptions: {
180+
pollingInterval: 15,
181+
skipPollingIfUnfocused: true,
182+
},
177183
subscribe: true,
178184
})
179185
)
@@ -182,7 +188,7 @@ describe('polling tests', () => {
182188
getPosts.initiate(3, {
183189
subscriptionOptions: {
184190
pollingInterval: 20,
185-
skipPollOnFocusLost: false,
191+
skipPollingIfUnfocused: false,
186192
},
187193
subscribe: true,
188194
})
@@ -197,13 +203,13 @@ describe('polling tests', () => {
197203
expect(callsWithSkip).toBe(callsWithoutSkip + 1)
198204
})
199205

200-
it('replaces skipPollOnFocusLost when the subscription options are updated', async () => {
206+
it('replaces skipPollingIfUnfocused when the subscription options are updated', async () => {
201207
const { requestId, queryCacheKey, ...subscription } =
202208
storeRef.store.dispatch(
203209
getPosts.initiate(1, {
204210
subscriptionOptions: {
205211
pollingInterval: 10,
206-
skipPollOnFocusLost: false,
212+
skipPollingIfUnfocused: false,
207213
},
208214
subscribe: true,
209215
})
@@ -213,15 +219,15 @@ describe('polling tests', () => {
213219

214220
await delay(1)
215221
expect(Object.keys(getSubs())).toHaveLength(1)
216-
expect(getSubs()[requestId].skipPollOnFocusLost).toBe(false)
222+
expect(getSubs()[requestId].skipPollingIfUnfocused).toBe(false)
217223

218224
subscription.updateSubscriptionOptions({
219225
pollingInterval: 20,
220-
skipPollOnFocusLost: true,
226+
skipPollingIfUnfocused: true,
221227
})
222228

223229
await delay(1)
224230
expect(Object.keys(getSubs())).toHaveLength(1)
225-
expect(getSubs()[requestId].skipPollOnFocusLost).toBe(true)
231+
expect(getSubs()[requestId].skipPollingIfUnfocused).toBe(true)
226232
})
227233
})

0 commit comments

Comments
 (0)