@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.
@@ -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 = { ...hasResult } as ResultType;
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(requestHash, restResult);
60
- }
61
- if (restResult.result === "error") {
62
- eventBus.emit("rest-error", restResult);
59
+ restStore.addResult(
60
+ requestHash,
61
+ JSON.parse(JSON.stringify(restResult)),
62
+ );
63
63
  }
64
64
  return Promise.resolve(restResult);
65
65
  } catch (error) {
@@ -21,7 +21,9 @@ export interface SSRResult {
21
21
  }
22
22
 
23
23
  export function isServerRendered() {
24
- return getInitialState().isSSR;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "0.0.944",
3
+ "version": "0.0.945",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {
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, APIResult | undefined>;
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: APIResult) {
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
  },