@spoosh/plugin-initial-data 0.1.4 → 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/README.md +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,11 +18,11 @@ import { initialDataPlugin } from "@spoosh/plugin-initial-data";
|
|
|
18
18
|
|
|
19
19
|
const client = new Spoosh<ApiSchema, Error>("/api").use([initialDataPlugin()]);
|
|
20
20
|
|
|
21
|
-
const { data, isInitialData } = useRead((api) => api.
|
|
21
|
+
const { data, isInitialData } = useRead((api) => api("posts").GET(), {
|
|
22
22
|
initialData: prefetchedPosts,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
const { data } = useRead((api) => api.
|
|
25
|
+
const { data } = useRead((api) => api("posts").GET(), {
|
|
26
26
|
initialData: prefetchedPosts,
|
|
27
27
|
refetchOnInitialData: false,
|
|
28
28
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -41,13 +41,13 @@ declare module "@spoosh/core" {
|
|
|
41
41
|
*
|
|
42
42
|
* // Basic usage - shows initialData, refetches in background
|
|
43
43
|
* const { data, isInitialData } = useRead(
|
|
44
|
-
* (api) => api.
|
|
44
|
+
* (api) => api("posts").GET(),
|
|
45
45
|
* { initialData: prefetchedPosts }
|
|
46
46
|
* );
|
|
47
47
|
*
|
|
48
48
|
* // Disable background refetch
|
|
49
49
|
* const { data } = useRead(
|
|
50
|
-
* (api) => api.
|
|
50
|
+
* (api) => api("posts").GET(),
|
|
51
51
|
* { initialData: prefetchedPosts, refetchOnInitialData: false }
|
|
52
52
|
* );
|
|
53
53
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -41,13 +41,13 @@ declare module "@spoosh/core" {
|
|
|
41
41
|
*
|
|
42
42
|
* // Basic usage - shows initialData, refetches in background
|
|
43
43
|
* const { data, isInitialData } = useRead(
|
|
44
|
-
* (api) => api.
|
|
44
|
+
* (api) => api("posts").GET(),
|
|
45
45
|
* { initialData: prefetchedPosts }
|
|
46
46
|
* );
|
|
47
47
|
*
|
|
48
48
|
* // Disable background refetch
|
|
49
49
|
* const { data } = useRead(
|
|
50
|
-
* (api) => api.
|
|
50
|
+
* (api) => api("posts").GET(),
|
|
51
51
|
* { initialData: prefetchedPosts, refetchOnInitialData: false }
|
|
52
52
|
* );
|
|
53
53
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function initialDataPlugin() {
|
|
|
35
35
|
if (pluginOptions?.initialData === void 0) {
|
|
36
36
|
const response2 = await next();
|
|
37
37
|
if (!response2.error) {
|
|
38
|
-
context.stateManager.
|
|
38
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
39
39
|
isInitialData: false
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ function initialDataPlugin() {
|
|
|
44
44
|
if (!context.hookId) {
|
|
45
45
|
const response2 = await next();
|
|
46
46
|
if (!response2.error) {
|
|
47
|
-
context.stateManager.
|
|
47
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
48
48
|
isInitialData: false
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -53,7 +53,7 @@ function initialDataPlugin() {
|
|
|
53
53
|
if (initialDataAppliedFor.has(context.hookId)) {
|
|
54
54
|
const response2 = await next();
|
|
55
55
|
if (!response2.error) {
|
|
56
|
-
context.stateManager.
|
|
56
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
57
57
|
isInitialData: false
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -64,7 +64,7 @@ function initialDataPlugin() {
|
|
|
64
64
|
initialDataAppliedFor.add(context.hookId);
|
|
65
65
|
const response2 = await next();
|
|
66
66
|
if (!response2.error) {
|
|
67
|
-
context.stateManager.
|
|
67
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
68
68
|
isInitialData: false
|
|
69
69
|
});
|
|
70
70
|
}
|
|
@@ -79,7 +79,7 @@ function initialDataPlugin() {
|
|
|
79
79
|
},
|
|
80
80
|
tags: context.tags
|
|
81
81
|
});
|
|
82
|
-
context.stateManager.
|
|
82
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
83
83
|
isInitialData: true
|
|
84
84
|
});
|
|
85
85
|
if (pluginOptions.refetchOnInitialData === false) {
|
|
@@ -87,7 +87,7 @@ function initialDataPlugin() {
|
|
|
87
87
|
}
|
|
88
88
|
const response = await next();
|
|
89
89
|
if (!response.error) {
|
|
90
|
-
context.stateManager.
|
|
90
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
91
91
|
isInitialData: false
|
|
92
92
|
});
|
|
93
93
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ function initialDataPlugin() {
|
|
|
9
9
|
if (pluginOptions?.initialData === void 0) {
|
|
10
10
|
const response2 = await next();
|
|
11
11
|
if (!response2.error) {
|
|
12
|
-
context.stateManager.
|
|
12
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
13
13
|
isInitialData: false
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -18,7 +18,7 @@ function initialDataPlugin() {
|
|
|
18
18
|
if (!context.hookId) {
|
|
19
19
|
const response2 = await next();
|
|
20
20
|
if (!response2.error) {
|
|
21
|
-
context.stateManager.
|
|
21
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
22
22
|
isInitialData: false
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ function initialDataPlugin() {
|
|
|
27
27
|
if (initialDataAppliedFor.has(context.hookId)) {
|
|
28
28
|
const response2 = await next();
|
|
29
29
|
if (!response2.error) {
|
|
30
|
-
context.stateManager.
|
|
30
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
31
31
|
isInitialData: false
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -38,7 +38,7 @@ function initialDataPlugin() {
|
|
|
38
38
|
initialDataAppliedFor.add(context.hookId);
|
|
39
39
|
const response2 = await next();
|
|
40
40
|
if (!response2.error) {
|
|
41
|
-
context.stateManager.
|
|
41
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
42
42
|
isInitialData: false
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -53,7 +53,7 @@ function initialDataPlugin() {
|
|
|
53
53
|
},
|
|
54
54
|
tags: context.tags
|
|
55
55
|
});
|
|
56
|
-
context.stateManager.
|
|
56
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
57
57
|
isInitialData: true
|
|
58
58
|
});
|
|
59
59
|
if (pluginOptions.refetchOnInitialData === false) {
|
|
@@ -61,7 +61,7 @@ function initialDataPlugin() {
|
|
|
61
61
|
}
|
|
62
62
|
const response = await next();
|
|
63
63
|
if (!response.error) {
|
|
64
|
-
context.stateManager.
|
|
64
|
+
context.stateManager.setMeta(context.queryKey, {
|
|
65
65
|
isInitialData: false
|
|
66
66
|
});
|
|
67
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-initial-data",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Initial data plugin for Spoosh - show data immediately before fetch completes",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@spoosh/core": ">=0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@spoosh/core": "0.
|
|
39
|
+
"@spoosh/core": "0.6.0",
|
|
40
40
|
"@spoosh/test-utils": "0.1.5"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|