Skip to content

Commit

Permalink
Refactoring how setIndex() generates data
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Nov 26, 2020
1 parent 582809a commit 053d946
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
33 changes: 20 additions & 13 deletions dist/haro.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,35 @@ function s () {
return ((Math.random() + 1) * 0x10000 | 0).toString(16).substring(1);
}

function setIndex (index, indexes, delimiter, key, data, indice, pattern) {
function setIndex (index, indexes, delimiter, key, data, indice) {
each(!indice ? index : [indice], i => {
const lindex = indexes.get(i);

if (Array.isArray(data[i]) && !i.includes(delimiter)) {
each(data[i], d => {
if (!lindex.has(d)) {
lindex.set(d, new Set());
if (i.includes(delimiter)) {
const keys = i.split(delimiter),
results = keys.reduce((a, li, lidx) => {
const result = [];

(Array.isArray(data[li]) ? data[li] : [data[li]]).forEach(lli => lidx === 0 ? result.push(lli) : a.forEach(x => result.push(`${x}|${lli}`)));

return result;
}, []);

each(results, c => {
if (!lindex.has(c)) {
lindex.set(c, new Set());
}

lindex.get(d).add(key);
lindex.get(c).add(key);
});
} else {
const lidx = keyIndex(i, data, delimiter, pattern);

if (lidx !== void 0 && lidx !== null) {
if (!lindex.has(lidx)) {
lindex.set(lidx, new Set());
each(Array.isArray(data[i]) ? data[i] : [data[i]], d => {
if (!lindex.has(d)) {
lindex.set(d, new Set());
}

lindex.get(lidx).add(key);
}
lindex.get(d).add(key);
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/haro.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 053d946

Please sign in to comment.