forked from verdnatura/salix-front
perf: revert processData
This commit is contained in:
parent
76b9fbc267
commit
d8c3e6bce7
|
@ -295,32 +295,28 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
}
|
||||
|
||||
function processData(data, { map = true, append = true }) {
|
||||
let newData;
|
||||
let newMap;
|
||||
if (!append) {
|
||||
newData = [];
|
||||
newMap = new Map();
|
||||
store.data = [];
|
||||
store.map = new Map();
|
||||
}
|
||||
|
||||
if (!Array.isArray(data)) newData = data;
|
||||
else if (!map && append) for (const row of data) newData.push(row);
|
||||
if (!Array.isArray(data)) store.data = data;
|
||||
else if (!map && append) for (const row of data) store.data.push(row);
|
||||
else
|
||||
for (const row of data) {
|
||||
const key = row[store.mapKey];
|
||||
const val = { ...row, key };
|
||||
if (key && newMap.has(key)) {
|
||||
if (key && store.map.has(key)) {
|
||||
const { position } = store.map.get(key);
|
||||
val.position = position;
|
||||
newMap.set(key, val);
|
||||
newData[position] = val;
|
||||
store.map.set(key, val);
|
||||
store.data[position] = val;
|
||||
} else {
|
||||
val.position = newMap.size;
|
||||
newMap.set(key, val);
|
||||
newData.push(val);
|
||||
val.position = store.map.size;
|
||||
store.map.set(key, val);
|
||||
store.data.push(val);
|
||||
}
|
||||
}
|
||||
store.data = data;
|
||||
store.map = map;
|
||||
}
|
||||
|
||||
const totalRows = computed(() => (store.data && store.data.length) || 0);
|
||||
|
|
Loading…
Reference in New Issue