#8113 create arrayDataStore map #979

Open
jorgep wants to merge 16 commits from 8113-preventDuplicateRecords into dev
1 changed files with 20 additions and 30 deletions
Showing only changes of commit a9cc6952d0 - Show all commits

View File

@ -124,38 +124,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
store.data = []; store.data = [];
store.map = new Map(); store.map = new Map();
} }
const totalRows = store.data.length; mapData(response.data);
response.data.forEach((row, position) => {
const key = row.clientFk;
const val = { ...row, key };
if (!store.map.has(key)) {
store.data.push({ ...val, position: totalRows + position });
} else {
const record = store.map.get(key);
const curPosition = record.position;
store.data[curPosition] = { ...val, position: curPosition };
}
store.map.set(key, val);
});
} else { } else {
store.data = []; store.data = [];
response.data.forEach((row) => { mapData(response.data);
const key = row.clientFk;
const val = { ...row, key };
if (store.map.has(key)) {
const { position } = store.map.get(key);
val.position = position;
store.map.set(key, val);
store.data[position] = val;
} else {
val.position = store.map.size;
store.map.set(key, val);
store.data.push(val);
}
});
if (!isDialogOpened()) updateRouter && updateStateParams(); if (!isDialogOpened()) updateRouter && updateStateParams();
} }
@ -320,6 +292,24 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
router.replace(newUrl); router.replace(newUrl);
} }
Review

Se podría usar ... pero he leído que en términos de rendimiento a la hora de manejar arrays muy grande es más rápido un for.

Se podría usar **...** pero he leído que en términos de rendimiento a la hora de manejar arrays muy grande es más rápido un for.
function mapData(data) {
data.forEach((row) => {
const key = row.clientFk;
const val = { ...row, key };
if (store.map.has(key)) {
const { position } = store.map.get(key);
val.position = position;
store.map.set(key, val);
store.data[position] = val;
} else {
val.position = store.map.size;
store.map.set(key, val);
store.data.push(val);
}
});
}
const totalRows = computed(() => (store.data && store.data.length) || 0); const totalRows = computed(() => (store.data && store.data.length) || 0);
const isLoading = computed(() => store.isLoading || false); const isLoading = computed(() => store.isLoading || false);