Skip to content

Commit 846f7f3

Browse files
committed
Reimplemented containsNonEmptyValues()
Changed to use a breadth-first search as suggested by @andywilkinshmcts, following code review.
1 parent 3b38077 commit 846f7f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/shared/services/form/form-value.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ export class FormValueService {
226226
*/
227227
private containsNonEmptyValues(object: object): boolean {
228228
const values = Object.keys(object).map(key => object[key]);
229-
return values.some(x => (x !== null &&
230-
(typeof x === 'object' && x.constructor === Object ? this.containsNonEmptyValues(x) : x !== '')));
229+
const objectRefs = [];
230+
// Note that pushing to an array is truthy (returns new length of the array), hence using ! to make it falsy
231+
const hasNonNullPrimitive = values.some(x => (x !== null &&
232+
(typeof x === 'object' && x.constructor === Object ? !objectRefs.push(x) : x !== '')));
233+
return !hasNonNullPrimitive ? objectRefs.some(y => this.containsNonEmptyValues(y)) : hasNonNullPrimitive;
231234
}
232235
}

0 commit comments

Comments
 (0)