@spoosh/plugin-polling 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -7
- package/dist/index.mjs +5 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Automatic polling/refetching plugin for Spoosh.
|
|
4
4
|
|
|
5
|
-
**[Documentation](https://spoosh.dev/docs/plugins/polling)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
5
|
+
**[Documentation](https://spoosh.dev/docs/react/plugins/polling)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
package/dist/index.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ declare module "@spoosh/core" {
|
|
|
23
23
|
* Automatically refetches data at specified intervals to keep it fresh.
|
|
24
24
|
* Supports dynamic intervals based on current data or error state.
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://spoosh.dev/docs/plugins/polling | Polling Plugin Documentation}
|
|
26
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/polling | Polling Plugin Documentation}
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare module "@spoosh/core" {
|
|
|
23
23
|
* Automatically refetches data at specified intervals to keep it fresh.
|
|
24
24
|
* Supports dynamic intervals based on current data or error state.
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://spoosh.dev/docs/plugins/polling | Polling Plugin Documentation}
|
|
26
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/polling | Polling Plugin Documentation}
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -34,15 +34,13 @@ function pollingPlugin() {
|
|
|
34
34
|
timeouts.delete(queryKey);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
const scheduleNextPoll = (context) => {
|
|
37
|
+
const scheduleNextPoll = (context, response) => {
|
|
38
38
|
const { queryKey, eventEmitter } = context;
|
|
39
39
|
const pluginOptions = context.pluginOptions;
|
|
40
40
|
const pollingInterval = pluginOptions?.pollingInterval;
|
|
41
41
|
if (!pollingInterval) return;
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const error = cached?.state.error;
|
|
45
|
-
const resolvedInterval = typeof pollingInterval === "function" ? pollingInterval(data, error) : pollingInterval;
|
|
42
|
+
const source = response ?? context.stateManager.getCache(queryKey)?.state;
|
|
43
|
+
const resolvedInterval = typeof pollingInterval === "function" ? pollingInterval(source?.data, source?.error) : pollingInterval;
|
|
46
44
|
if (resolvedInterval === false || resolvedInterval <= 0) return;
|
|
47
45
|
clearPolling(queryKey);
|
|
48
46
|
const timeout = setTimeout(() => {
|
|
@@ -57,8 +55,8 @@ function pollingPlugin() {
|
|
|
57
55
|
return {
|
|
58
56
|
name: "spoosh:polling",
|
|
59
57
|
operations: ["read", "infiniteRead"],
|
|
60
|
-
afterResponse(context) {
|
|
61
|
-
scheduleNextPoll(context);
|
|
58
|
+
afterResponse(context, response) {
|
|
59
|
+
scheduleNextPoll(context, response);
|
|
62
60
|
},
|
|
63
61
|
lifecycle: {
|
|
64
62
|
onUpdate(context, previousContext) {
|
package/dist/index.mjs
CHANGED
|
@@ -8,15 +8,13 @@ function pollingPlugin() {
|
|
|
8
8
|
timeouts.delete(queryKey);
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
const scheduleNextPoll = (context) => {
|
|
11
|
+
const scheduleNextPoll = (context, response) => {
|
|
12
12
|
const { queryKey, eventEmitter } = context;
|
|
13
13
|
const pluginOptions = context.pluginOptions;
|
|
14
14
|
const pollingInterval = pluginOptions?.pollingInterval;
|
|
15
15
|
if (!pollingInterval) return;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const error = cached?.state.error;
|
|
19
|
-
const resolvedInterval = typeof pollingInterval === "function" ? pollingInterval(data, error) : pollingInterval;
|
|
16
|
+
const source = response ?? context.stateManager.getCache(queryKey)?.state;
|
|
17
|
+
const resolvedInterval = typeof pollingInterval === "function" ? pollingInterval(source?.data, source?.error) : pollingInterval;
|
|
20
18
|
if (resolvedInterval === false || resolvedInterval <= 0) return;
|
|
21
19
|
clearPolling(queryKey);
|
|
22
20
|
const timeout = setTimeout(() => {
|
|
@@ -31,8 +29,8 @@ function pollingPlugin() {
|
|
|
31
29
|
return {
|
|
32
30
|
name: "spoosh:polling",
|
|
33
31
|
operations: ["read", "infiniteRead"],
|
|
34
|
-
afterResponse(context) {
|
|
35
|
-
scheduleNextPoll(context);
|
|
32
|
+
afterResponse(context, response) {
|
|
33
|
+
scheduleNextPoll(context, response);
|
|
36
34
|
},
|
|
37
35
|
lifecycle: {
|
|
38
36
|
onUpdate(context, previousContext) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-polling",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Automatic polling/refetching plugin for Spoosh",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/spooshdev/spoosh.git",
|
|
9
9
|
"directory": "packages/plugin-polling"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/spooshdev/spoosh/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://spoosh.dev/react/
|
|
14
|
+
"homepage": "https://spoosh.dev/docs/react/plugins/polling",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@spoosh/core": ">=0.8.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@spoosh/core": "0.
|
|
40
|
+
"@spoosh/core": "0.10.0",
|
|
41
41
|
"@spoosh/test-utils": "0.1.5"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|