Skip to content

Commit

Permalink
Merge pull request #117 from tjinauyeung/fix/add-tests-for-isvalid-on…
Browse files Browse the repository at this point in the history
…-nested-arrays
  • Loading branch information
larrybotha authored May 1, 2021
2 parents 22f948a + 03482d6 commit f846e04
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 69 deletions.
17 changes: 10 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {dequal as isEqual} from 'dequal/lite';

function subscribeOnce(observable) {
return new Promise((resolve) => {
return new Promise(resolve => {
observable.subscribe(resolve)(); // immediately invoke to unsubscribe
});
}

function update(object, path, value) {
object.update((o) => {
object.update(o => {
set(o, path, value);
return o;
});
Expand All @@ -26,11 +26,14 @@ function isEmpty(object) {
}

function getValues(object) {
let result = [];
let results = [];

for (const [, value] of Object.entries(object)) {
result = [...result, ...(typeof value === 'object' ? getValues(value) : [value])];
const values = typeof value === 'object' ? getValues(value) : [value];
results = [...results, ...values];
}
return result;

return results;
}

// TODO: refactor this so as not to rely directly on yup's API
Expand All @@ -51,7 +54,7 @@ function getErrorsFromSchema(initialValues, schema, errors = {}) {
case schema[key].type === 'array': {
const values =
initialValues && initialValues[key] ? initialValues[key] : [];
errors[key] = values.map((value) =>
errors[key] = values.map(value =>
getErrorsFromSchema(
value,
schema[key].innerType.fields,
Expand All @@ -74,7 +77,7 @@ const deepEqual = isEqual;

function assignDeep(object, value) {
if (Array.isArray(object)) {
return object.map((o) => assignDeep(o, value));
return object.map(o => assignDeep(o, value));
}
const copy = {};
for (const key in object) {
Expand Down
Loading

0 comments on commit f846e04

Please sign in to comment.