Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent bf4296f commit 92aaf82
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/config/normalize/lib/wild_wild_path/iterate/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,33 @@ export const iterate = function* (

const iterateLevel = function* (entries, index, opts) {
const entriesA = removeDuplicates(entries)
const parentEntries = getParentEntries(entriesA, index)
const parentEntry = getParentEntry(entriesA, index)

if (!opts.childFirst) {
yield* parentEntries
if (parentEntry !== undefined && !opts.childFirst) {
yield parentEntry
}

yield* iterateChildEntries({ entries, parentEntries, index, opts })
yield* iterateChildEntries({ entries: entriesA, parentEntry, index, opts })

if (opts.childFirst) {
yield* parentEntries
if (parentEntry !== undefined && opts.childFirst) {
yield parentEntry
}
}

const getParentEntries = function (entries, index) {
return entries
.filter(({ queryArray }) => queryArray.length === index)
.map(normalizeEntry)
const getParentEntry = function (entries, index) {
const parentEntry = entries.find(
({ queryArray }) => queryArray.length === index,
)
return parentEntry === undefined ? undefined : normalizeEntry(parentEntry)
}

const normalizeEntry = function ({ value, path, missing }) {
const query = serializePath(path)
return { value, path, query, missing }
}

const iterateChildEntries = function* ({
entries,
parentEntries,
index,
opts,
}) {
if (parentEntries.length === entries.length) {
const iterateChildEntries = function* ({ entries, parentEntry, index, opts }) {
if (parentEntry !== undefined && entries.length === 1) {
return
}

Expand Down

0 comments on commit 92aaf82

Please sign in to comment.