@fy-/fws-vue 0.0.944 → 0.0.945
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/composables/rest.ts +5 -5
- package/composables/ssr.ts +3 -1
- package/package.json +1 -1
- package/stores/rest.ts +5 -2
package/composables/rest.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function useRest(): <ResultType extends APIResult>(
|
|
|
43
43
|
if (isServerRendered()) {
|
|
44
44
|
const hasResult = restStore.getResult(requestHash);
|
|
45
45
|
if (hasResult !== undefined) {
|
|
46
|
-
const result =
|
|
46
|
+
const result = hasResult as ResultType;
|
|
47
47
|
restStore.removeResult(requestHash);
|
|
48
48
|
if (result.result === "error") {
|
|
49
49
|
eventBus.emit("rest-error", result);
|
|
@@ -56,10 +56,10 @@ export function useRest(): <ResultType extends APIResult>(
|
|
|
56
56
|
try {
|
|
57
57
|
const restResult: ResultType = await rest(url, method, params);
|
|
58
58
|
if (getMode() === "ssr") {
|
|
59
|
-
restStore.addResult(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
restStore.addResult(
|
|
60
|
+
requestHash,
|
|
61
|
+
JSON.parse(JSON.stringify(restResult)),
|
|
62
|
+
);
|
|
63
63
|
}
|
|
64
64
|
return Promise.resolve(restResult);
|
|
65
65
|
} catch (error) {
|
package/composables/ssr.ts
CHANGED
|
@@ -21,7 +21,9 @@ export interface SSRResult {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function isServerRendered() {
|
|
24
|
-
|
|
24
|
+
const state = getInitialState();
|
|
25
|
+
if (state && state.isSSR) return true;
|
|
26
|
+
return false;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export function initVueClient(router: Router, pinia: Pinia) {
|
package/package.json
CHANGED
package/stores/rest.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { defineStore } from "pinia";
|
|
|
2
2
|
import { APIResult } from "../composables/rest";
|
|
3
3
|
|
|
4
4
|
type SharedState = {
|
|
5
|
-
results: Record<number,
|
|
5
|
+
results: Record<number, any | undefined>;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export const useRestStore = defineStore({
|
|
@@ -11,9 +11,12 @@ export const useRestStore = defineStore({
|
|
|
11
11
|
results: {},
|
|
12
12
|
}),
|
|
13
13
|
actions: {
|
|
14
|
-
addResult(id: number, result:
|
|
14
|
+
addResult(id: number, result: any) {
|
|
15
15
|
this.results[id] = result;
|
|
16
16
|
},
|
|
17
|
+
hasResult(id: number) {
|
|
18
|
+
return this.results[id] !== undefined;
|
|
19
|
+
},
|
|
17
20
|
getResult(id: number) {
|
|
18
21
|
return this.results[id];
|
|
19
22
|
},
|