7729-devToTest_2430 #554

Merged
alexm merged 401 commits from 7729-devToTest_2430 into test 2024-07-16 07:17:04 +00:00
2 changed files with 31 additions and 15 deletions
Showing only changes of commit 9956561e4c - Show all commits

View File

@ -130,6 +130,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
delete store[option];
}
function reset(opts = []) {
if (arrayDataStore.get(key)) arrayDataStore.reset(key, opts);
}
function cancelRequest() {
if (canceller) {
canceller.abort();
@ -245,5 +249,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
updateStateParams,
isLoading,
deleteOption,
reset,
};
}

View File

@ -3,36 +3,47 @@ import { defineStore } from 'pinia';
export const useArrayDataStore = defineStore('arrayDataStore', () => {
const state = ref({});
const defaultOpts = {
filter: {},
userFilter: {},
userParams: {},
url: '',
limit: 10,
skip: 0,
order: '',
data: ref(),
isLoading: false,
userParamsChanged: false,
exprBuilder: null,
searchUrl: 'params',
navigate: null,
};
function get(key) {
return state.value[key];
}
function set(key) {
state.value[key] = {
filter: {},
userFilter: {},
userParams: {},
url: '',
limit: 10,
skip: 0,
order: '',
data: ref(),
isLoading: false,
userParamsChanged: false,
exprBuilder: null,
searchUrl: 'params',
navigate: null,
};
state.value[key] = defaultOpts;
}
function clear(key) {
delete state.value[key];
}
function reset(key, opts = []) {
let obj = state.value[key];
if (!opts.length) obj = defaultOpts;
else
for (const opt in opts) {
if (Object.hasOwn(obj, opt)) obj[opt] = defaultOpts[opt];
}
}
return {
get,
set,
clear,
reset,
};
});