Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Apr 3, 2022
1 parent abd2397 commit d8ee2b2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/iterate/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ import { isAllowedProp } from './expand.js'
import { MISSING_HANDLERS } from './missing.js'

// Performance-optimized `iterate()` logic when the query is a path
export const iteratePath = function* (
export const iteratePath = function* (target, pathArray, opts) {
const { entry, matches } = getPathValue(target, pathArray, opts)

if (matches) {
yield entry
}
}

const getPathValue = function (
target,
pathArray,
{ missing: missingOpt, entries },
) {
const { value, missing } = getDeepValue(target, pathArray)

if (!missing || missingOpt) {
yield entries ? { value, path: pathArray, missing } : value
if (missing && !missingOpt) {
return { matches: false }
}

const entry = entries ? { value, path: pathArray, missing } : value
return { entry, matches: true }
}

const getDeepValue = function (value, pathArray) {
Expand Down

0 comments on commit d8ee2b2

Please sign in to comment.