Skip to content

Commit c34dd0a

Browse files
committed
fix: change refocusExchange to use an options object
chore: docs
1 parent 939e55b commit c34dd0a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

exchanges/refocus/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import { refocusExchange } from '@urql/exchange-refocus';
2222

2323
const client = createClient({
2424
url: 'http://localhost:3000/graphql',
25-
exchanges: [refocusExchange(), cacheExchange, fetchExchange],
25+
exchanges: [refocusExchange({
26+
// The minimum time in milliseconds to wait before another refocus can trigger. Default value is 0.
27+
minimumTime: 2000
28+
}), cacheExchange, fetchExchange],
2629
});
2730
```

exchanges/refocus/src/refocusExchange.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { pipe, tap } from 'wonka';
22
import type { Exchange, Operation } from '@urql/core';
33

4+
export interface RefocusOptions {
5+
/** The minimum time in milliseconds to wait before another refocus can trigger.
6+
* @defaultValue `0`
7+
*/
8+
minimumTime?: number;
9+
}
10+
411
/** Exchange factory that reexecutes operations after a user returns to the tab.
512
*
6-
* @param minimumTime - The minimum time in milliseconds to wait before another refocus can trigger.
13+
* @param opts - A {@link RefocusOptions} configuration object.
714
*
815
* @returns a new refocus {@link Exchange}.
916
*
@@ -16,7 +23,9 @@ import type { Exchange, Operation } from '@urql/core';
1623
* The `cache-and-network` policy will refetch data in the background, but will
1724
* only refetch queries that are currently active.
1825
*/
19-
export const refocusExchange = (minimumTime = 0): Exchange => {
26+
export const refocusExchange = (opts: RefocusOptions = {}): Exchange => {
27+
const { minimumTime = 0 } = opts;
28+
2029
return ({ client, forward }) =>
2130
ops$ => {
2231
if (typeof window === 'undefined') {

0 commit comments

Comments
 (0)