@statezero/core 0.1.35 → 0.1.36
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.
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { computed, getCurrentInstance, onBeforeUnmount } from
|
|
2
|
-
import { querysetStoreRegistry } from
|
|
3
|
-
import { metricRegistry } from
|
|
4
|
-
import { syncManager } from
|
|
5
|
-
import {
|
|
1
|
+
import { computed, getCurrentInstance, onBeforeUnmount } from "vue";
|
|
2
|
+
import { querysetStoreRegistry } from "../../syncEngine/registries/querysetStoreRegistry";
|
|
3
|
+
import { metricRegistry } from "../../syncEngine/registries/metricRegistry";
|
|
4
|
+
import { syncManager } from "../../syncEngine/sync";
|
|
5
|
+
import { wrappedQuerysetCache } from "./reactivity.js";
|
|
6
|
+
import { v7 } from "uuid";
|
|
6
7
|
syncManager.followAllQuerysets = false;
|
|
7
8
|
export const querysets = new Map(); // Map of composableId -> queryset
|
|
8
9
|
function updateSyncManager() {
|
|
@@ -13,11 +14,16 @@ function updateSyncManager() {
|
|
|
13
14
|
export function useQueryset(querysetFactory) {
|
|
14
15
|
const instance = getCurrentInstance();
|
|
15
16
|
if (!instance) {
|
|
16
|
-
throw new Error(
|
|
17
|
+
throw new Error("useQueryset must be called within a component setup function");
|
|
17
18
|
}
|
|
18
19
|
const composableId = v7();
|
|
19
20
|
let lastQueryset = null;
|
|
20
21
|
onBeforeUnmount(() => {
|
|
22
|
+
// Clear cache when component unmounts
|
|
23
|
+
if (lastQueryset?.semanticKey &&
|
|
24
|
+
wrappedQuerysetCache.has(lastQueryset.semanticKey)) {
|
|
25
|
+
wrappedQuerysetCache.delete(lastQueryset.semanticKey);
|
|
26
|
+
}
|
|
21
27
|
querysets.delete(composableId);
|
|
22
28
|
updateSyncManager();
|
|
23
29
|
});
|
|
@@ -27,6 +33,12 @@ export function useQueryset(querysetFactory) {
|
|
|
27
33
|
const queryset = original?.queryset || original;
|
|
28
34
|
// Only update if queryset actually changed
|
|
29
35
|
if (lastQueryset !== queryset) {
|
|
36
|
+
// Clear cache for previous queryset if it changed
|
|
37
|
+
if (lastQueryset?.semanticKey &&
|
|
38
|
+
lastQueryset !== queryset &&
|
|
39
|
+
wrappedQuerysetCache.has(lastQueryset.semanticKey)) {
|
|
40
|
+
wrappedQuerysetCache.delete(lastQueryset.semanticKey);
|
|
41
|
+
}
|
|
30
42
|
querysets.set(composableId, queryset);
|
|
31
43
|
updateSyncManager();
|
|
32
44
|
lastQueryset = queryset;
|
|
@@ -16,3 +16,4 @@ export function ModelAdaptor(modelInstance: Object, reactivityFn?: Function): an
|
|
|
16
16
|
*/
|
|
17
17
|
export function QuerySetAdaptor(liveQuerySet: Object, reactivityFn?: Function): any | import("vue").Ref;
|
|
18
18
|
export function MetricAdaptor(metric: any): any;
|
|
19
|
+
export const wrappedQuerysetCache: Map<any, any>;
|
package/package.json
CHANGED