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

View File

@ -3,13 +3,7 @@ import { defineStore } from 'pinia';
export const useArrayDataStore = defineStore('arrayDataStore', () => { export const useArrayDataStore = defineStore('arrayDataStore', () => {
const state = ref({}); const state = ref({});
const defaultOpts = {
function get(key) {
return state.value[key];
}
function set(key) {
state.value[key] = {
filter: {}, filter: {},
userFilter: {}, userFilter: {},
userParams: {}, userParams: {},
@ -24,15 +18,32 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
searchUrl: 'params', searchUrl: 'params',
navigate: null, navigate: null,
}; };
function get(key) {
return state.value[key];
}
function set(key) {
state.value[key] = defaultOpts;
} }
function clear(key) { function clear(key) {
delete state.value[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 { return {
get, get,
set, set,
clear, clear,
reset,
}; };
}); });