Skip to content

Commit

Permalink
Add missing to map()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent 3099b61 commit a0b43d0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/config/normalize/lib/wild_wild_path_utils/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,43 @@ export const map = function (
target,
query,
mapFunc,
{ mutate, classes, inherited } = {},
{ mutate, missing, classes, inherited } = {},
) {
const entries = list(target, query, {
childFirst: true,
sort: false,
missing,
classes,
inherited,
})
return entries.reduce(
(targetA, entry) =>
mapEntry({ mapFunc, target: targetA, entry, mutate, classes, inherited }),
mapEntry({
mapFunc,
target: targetA,
entry,
mutate,
missing,
classes,
inherited,
}),
target,
)
}

const mapEntry = function ({
mapFunc,
target,
entry: { path, query, missing },
entry,
entry: { path },
mutate,
missing,
classes,
inherited,
}) {
const value = get(target, path, { classes, inherited })
const mappedValue = mapFunc({ path, query, value, missing })
const value = get(target, path, { missing, classes, inherited })
const mappedValue = mapFunc({ ...entry, value })
return value === mappedValue
? target
: set(target, path, mappedValue, { mutate, classes, inherited })
: set(target, path, mappedValue, { mutate, missing, classes, inherited })
}

0 comments on commit a0b43d0

Please sign in to comment.