gemi 0.28.1 → 0.28.2
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/client/QueryResource.d.ts +2 -1
- package/dist/client/QueryResource.d.ts.map +1 -1
- package/dist/client/index.js +26 -8
- package/dist/client/index.js.map +1 -1
- package/dist/client/useQuery.d.ts +3 -2
- package/dist/client/useQuery.d.ts.map +1 -1
- package/dist/facades/index.js +8 -8
- package/dist/facades/index.js.map +4 -4
- package/dist/http/ViewRouter.d.ts +5 -2
- package/dist/http/ViewRouter.d.ts.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +3 -3
- package/dist/services/router/ViewRouterServiceContainer.d.ts.map +1 -1
- package/dist/services/router/createComponentTree.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ type State = {
|
|
|
3
3
|
loading: boolean;
|
|
4
4
|
data: any;
|
|
5
5
|
error: any;
|
|
6
|
+
version: number;
|
|
6
7
|
};
|
|
7
8
|
export declare class QueryResource {
|
|
8
9
|
store: Subject<Map<string, State>>;
|
|
@@ -13,7 +14,7 @@ export declare class QueryResource {
|
|
|
13
14
|
host: string;
|
|
14
15
|
constructor(key: string, initialState: Record<string, any>, fetch: typeof globalThis.fetch, host: string);
|
|
15
16
|
getVariant(variantKey: string): State;
|
|
16
|
-
mutate(variantKey: string, fn
|
|
17
|
+
mutate(variantKey: string, fn?: (data: any) => any): void;
|
|
17
18
|
private resolveVariant;
|
|
18
19
|
}
|
|
19
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResource.d.ts","sourceRoot":"","sources":["../../client/QueryResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryResource.d.ts","sourceRoot":"","sources":["../../client/QueryResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,aAAa;IACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACnC,aAAa,cAAqB;IAClC,eAAe,sBAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;gBAGX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,IAAI,EAAE,MAAM;IAqBd,UAAU,CAAC,UAAU,EAAE,MAAM;IAgC7B,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,GAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAoB;YA6BpD,cAAc;CA8D7B"}
|
package/dist/client/index.js
CHANGED
|
@@ -68,7 +68,8 @@ class QueryResource {
|
|
|
68
68
|
if (!variant.data) {
|
|
69
69
|
this.resolveVariant(variantKey);
|
|
70
70
|
return store.get(variantKey);
|
|
71
|
-
}
|
|
71
|
+
}
|
|
72
|
+
if (variant.data) {
|
|
72
73
|
const stale = this.staleVariants.has(variantKey);
|
|
73
74
|
const now = Date.now();
|
|
74
75
|
const old = now - (this.lastFetchRecord.get(variantKey) ?? now) > 5e3;
|
|
@@ -82,7 +83,7 @@ class QueryResource {
|
|
|
82
83
|
}
|
|
83
84
|
return store.get(variantKey);
|
|
84
85
|
}
|
|
85
|
-
mutate(variantKey, fn) {
|
|
86
|
+
mutate(variantKey, fn = (data) => data) {
|
|
86
87
|
const cacheKey = [window.location.origin, this.key, variantKey].filter((s) => s.length > 0).join("?");
|
|
87
88
|
try {
|
|
88
89
|
if (caches) {
|
|
@@ -98,7 +99,12 @@ class QueryResource {
|
|
|
98
99
|
const data = fn(state.data);
|
|
99
100
|
this.staleVariants.add(variantKey);
|
|
100
101
|
this.store.next(
|
|
101
|
-
store.set(variantKey, {
|
|
102
|
+
store.set(variantKey, {
|
|
103
|
+
loading: false,
|
|
104
|
+
data,
|
|
105
|
+
error: null,
|
|
106
|
+
version: state.version
|
|
107
|
+
})
|
|
102
108
|
);
|
|
103
109
|
this.resolveVariant(variantKey, false, false);
|
|
104
110
|
}
|
|
@@ -112,7 +118,8 @@ class QueryResource {
|
|
|
112
118
|
store.set(variantKey, {
|
|
113
119
|
loading: true,
|
|
114
120
|
data: previousState == null ? void 0 : previousState.data,
|
|
115
|
-
error: previousState == null ? void 0 : previousState.data
|
|
121
|
+
error: previousState == null ? void 0 : previousState.data,
|
|
122
|
+
version: previousState == null ? void 0 : previousState.version
|
|
116
123
|
});
|
|
117
124
|
}
|
|
118
125
|
const fullUrl = [this.key, variantKey].filter((s) => s.length).join("?");
|
|
@@ -127,13 +134,19 @@ class QueryResource {
|
|
|
127
134
|
store.set(variantKey, {
|
|
128
135
|
loading: false,
|
|
129
136
|
data: previousState == null ? void 0 : previousState.data,
|
|
130
|
-
error
|
|
137
|
+
error,
|
|
138
|
+
version: previousState == null ? void 0 : previousState.version
|
|
131
139
|
})
|
|
132
140
|
);
|
|
133
141
|
}
|
|
134
142
|
if (response.ok) {
|
|
135
143
|
this.store.next(
|
|
136
|
-
store.set(variantKey, {
|
|
144
|
+
store.set(variantKey, {
|
|
145
|
+
loading: false,
|
|
146
|
+
data,
|
|
147
|
+
error: null,
|
|
148
|
+
version: Date.now()
|
|
149
|
+
})
|
|
137
150
|
);
|
|
138
151
|
this.staleVariants.delete(variantKey);
|
|
139
152
|
this.lastFetchRecord.set(variantKey, Date.now());
|
|
@@ -142,7 +155,8 @@ class QueryResource {
|
|
|
142
155
|
store.set(variantKey, {
|
|
143
156
|
loading: false,
|
|
144
157
|
data: previousState == null ? void 0 : previousState.data,
|
|
145
|
-
error: data
|
|
158
|
+
error: data,
|
|
159
|
+
version: previousState == null ? void 0 : previousState.version
|
|
146
160
|
})
|
|
147
161
|
);
|
|
148
162
|
}
|
|
@@ -337,6 +351,9 @@ function useQuery(url, ...args) {
|
|
|
337
351
|
};
|
|
338
352
|
}, [variantKey, resource, handleStateUpdate]);
|
|
339
353
|
function mutate(fn) {
|
|
354
|
+
if (!fn) {
|
|
355
|
+
return resource.mutate.call(resource, variantKey, (data) => data);
|
|
356
|
+
}
|
|
340
357
|
return resource.mutate.call(resource, variantKey, (data) => {
|
|
341
358
|
if (data === void 0 || data === null) {
|
|
342
359
|
console.warn("Mutate function called before the query.");
|
|
@@ -371,7 +388,8 @@ function useQuery(url, ...args) {
|
|
|
371
388
|
data: state == null ? void 0 : state.data,
|
|
372
389
|
loading: (state == null ? void 0 : state.loading) ?? true,
|
|
373
390
|
error: state == null ? void 0 : state.error,
|
|
374
|
-
mutate
|
|
391
|
+
mutate,
|
|
392
|
+
version: state == null ? void 0 : state.version
|
|
375
393
|
};
|
|
376
394
|
}
|
|
377
395
|
function applyParams(url, params = {}) {
|