@spoosh/plugin-polling 0.1.4 → 0.2.0
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 +4 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@ import { pollingPlugin } from "@spoosh/plugin-polling";
|
|
|
19
19
|
const client = new Spoosh<ApiSchema, Error>("/api").use([pollingPlugin()]);
|
|
20
20
|
|
|
21
21
|
// Static polling interval (5 seconds)
|
|
22
|
-
useRead((api) => api.
|
|
22
|
+
useRead((api) => api("posts").GET(), { pollingInterval: 5000 });
|
|
23
23
|
|
|
24
24
|
// Disable polling (Default behavior)
|
|
25
|
-
useRead((api) => api.
|
|
25
|
+
useRead((api) => api("posts").GET(), { pollingInterval: false });
|
|
26
26
|
|
|
27
27
|
// Dynamic polling interval based on data/error
|
|
28
|
-
useRead((api) => api.
|
|
28
|
+
useRead((api) => api("booking/:id").GET({ params: { id: 123 } }), {
|
|
29
29
|
pollingInterval: (data, error) => {
|
|
30
30
|
if (error) return 10000; // Slower polling on error
|
|
31
31
|
if (data?.status === "pending") return 1000; // Fast polling for pending
|
|
@@ -47,7 +47,7 @@ useRead((api) => api.booking(123).$get(), {
|
|
|
47
47
|
The polling interval can be a function that receives the current data and error, allowing you to adjust the polling rate based on the response:
|
|
48
48
|
|
|
49
49
|
```typescript
|
|
50
|
-
useRead((api) => api
|
|
50
|
+
useRead((api) => api("jobs/:id").GET({ params: { id: jobId } }), {
|
|
51
51
|
pollingInterval: (data) => {
|
|
52
52
|
// Stop polling when job is complete
|
|
53
53
|
if (data?.status === "completed") return false;
|
package/dist/index.d.mts
CHANGED
|
@@ -36,12 +36,12 @@ declare module "@spoosh/core" {
|
|
|
36
36
|
* ]);
|
|
37
37
|
*
|
|
38
38
|
* // Poll every 5 seconds
|
|
39
|
-
* useRead((api) => api.
|
|
39
|
+
* useRead((api) => api("posts").GET(), {
|
|
40
40
|
* pollingInterval: 5000,
|
|
41
41
|
* });
|
|
42
42
|
*
|
|
43
43
|
* // Dynamic interval based on data
|
|
44
|
-
* useRead((api) => api.
|
|
44
|
+
* useRead((api) => api("posts").GET(), {
|
|
45
45
|
* pollingInterval: (data, error) => error ? 10000 : 5000,
|
|
46
46
|
* });
|
|
47
47
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -36,12 +36,12 @@ declare module "@spoosh/core" {
|
|
|
36
36
|
* ]);
|
|
37
37
|
*
|
|
38
38
|
* // Poll every 5 seconds
|
|
39
|
-
* useRead((api) => api.
|
|
39
|
+
* useRead((api) => api("posts").GET(), {
|
|
40
40
|
* pollingInterval: 5000,
|
|
41
41
|
* });
|
|
42
42
|
*
|
|
43
43
|
* // Dynamic interval based on data
|
|
44
|
-
* useRead((api) => api.
|
|
44
|
+
* useRead((api) => api("posts").GET(), {
|
|
45
45
|
* pollingInterval: (data, error) => error ? 10000 : 5000,
|
|
46
46
|
* });
|
|
47
47
|
* ```
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-polling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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.0",
|
|
41
41
|
"@spoosh/test-utils": "0.1.5"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|