fix: Stores Not Populating Sometimes (#6266)

This commit is contained in:
Michael Genson
2025-09-27 19:17:08 -05:00
committed by GitHub
parent e3f120c680
commit 824603a578
13 changed files with 31 additions and 27 deletions

View File

@@ -13,12 +13,13 @@ export const useData = function <T extends BoundT>(defaultObject: T) {
};
export const useReadOnlyStore = function <T extends BoundT>(
storeKey: string,
store: Ref<T[]>,
loading: Ref<boolean>,
api: BaseCRUDAPIReadOnly<T>,
params = {} as Record<string, QueryValue>,
) {
const storeActions = useReadOnlyActions(api, store, loading);
const storeActions = useReadOnlyActions(`${storeKey}-store-readonly`, api, store, loading);
const actions = {
...storeActions,
async refresh() {
@@ -29,21 +30,22 @@ export const useReadOnlyStore = function <T extends BoundT>(
},
};
// initial hydration
if (!loading.value && !store.value.length) {
const result = actions.getAll(1, -1, params);
store.value = result.value || [];
actions.refresh();
}
return { store, actions };
};
export const useStore = function <T extends BoundT>(
storeKey: string,
store: Ref<T[]>,
loading: Ref<boolean>,
api: BaseCRUDAPI<unknown, T, unknown>,
params = {} as Record<string, QueryValue>,
) {
const storeActions = useStoreActions(api, store, loading);
const storeActions = useStoreActions(`${storeKey}-store`, api, store, loading);
const actions = {
...storeActions,
async refresh() {
@@ -54,9 +56,9 @@ export const useStore = function <T extends BoundT>(
},
};
// initial hydration
if (!loading.value && !store.value.length) {
const result = actions.getAll(1, -1, params);
store.value = result.value || [];
actions.refresh();
}
return { store, actions };