@spoosh/plugin-polling 0.1.5 → 0.2.1
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/dist/index.js +5 -7
- package/dist/index.mjs +5 -7
- package/package.json +3 -3
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
|
-
|
|
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
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-polling",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Automatic polling/refetching plugin for Spoosh",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@spoosh/core": ">=0.
|
|
37
|
+
"@spoosh/core": ">=0.8.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@spoosh/core": "0.
|
|
40
|
+
"@spoosh/core": "0.8.2",
|
|
41
41
|
"@spoosh/test-utils": "0.1.5"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|