Skip to content

Commit

Permalink
Improved computed-fields function
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurczewski committed Oct 7, 2024
1 parent 807d57c commit e169e11
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions libs/generic-view/store/src/lib/entities/helpers/compute-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export const computeField = (
if (field.endsWith("[]")) {
return [...acc, ...(get(entity, field.slice(0, -2)) as unknown[])]
}
return [...acc, get(entity, field)]
acc.push(get(entity, field))
return acc
}
return [...acc, computeField(entity, field)]
acc.push(computeField(entity, field))
return acc
}, [])

switch (type) {
Expand All @@ -44,26 +46,24 @@ export const computeField = (
})
}
case "clear": {
return values
.filter((value) => {
const emptyStringCondition = config.allowEmptyString || value !== ""
const zeroCondition = config.allowZero || value !== 0
const falseCondition = config.allowFalse || value !== false
const undefinedCondition = value !== undefined
const emptyArrayCondition = isArray(value) ? value.length !== 0 : true
const emptyObjectCondition = isObject(value)
? Object.keys(value).length !== 0
: true
return (
undefinedCondition &&
emptyStringCondition &&
emptyArrayCondition &&
emptyObjectCondition &&
zeroCondition &&
falseCondition
)
})
.map((value) => (value === undefined ? [] : value))
return values.filter((value) => {
const emptyStringCondition = config.allowEmptyString || value !== ""
const zeroCondition = config.allowZero || value !== 0
const falseCondition = config.allowFalse || value !== false
const undefinedCondition = value !== undefined
const emptyArrayCondition = isArray(value) ? value.length !== 0 : true
const emptyObjectCondition = isObject(value)
? Object.keys(value).length !== 0
: true
return (
undefinedCondition &&
emptyStringCondition &&
emptyArrayCondition &&
emptyObjectCondition &&
zeroCondition &&
falseCondition
)
})
}
case "slice":
return slice(values, config.start, config.end)
Expand Down

0 comments on commit e169e11

Please sign in to comment.