Skip to content

Commit

Permalink
Add roots to remove|set()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent 53c6527 commit 31b9c3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/config/normalize/lib/wild_wild_path/remove.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { validateClasses, reduceParents, setValue } from './set.js'
import { reduceParents, setValue } from './set.js'
import { validateClasses } from './validate.js'

// Same as `set()` but removing a value
export const remove = function (
Expand Down
16 changes: 4 additions & 12 deletions src/config/normalize/lib/wild_wild_path/set.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isParentPath } from '../wild_wild_path_parser/main.js'

import { list } from './get.js'
import { getMissingValue } from './iterate/missing.js'
import { validateClasses } from './validate.js'
Expand Down Expand Up @@ -31,21 +29,15 @@ export const reduceParents = function ({
}) {
const entries = list(target, query, {
childFirst: false,
roots: true,
sort: false,
missing,
classes,
inherited,
})
return entries
.filter(hasNoParentSet)
.reduce((targetA, { path }) => setFunc(targetA, path, 0), target)
}

// If both a parent and a child property are set, the parent prevails
const hasNoParentSet = function ({ path: pathA }, indexA, entries) {
return entries.every(
({ path: pathB }, indexB) =>
indexA <= indexB || !isParentPath(pathB, pathA),
return entries.reduce(
(targetA, { path }) => setFunc(targetA, path, 0),
target,
)
}

Expand Down

0 comments on commit 31b9c3a

Please sign in to comment.