@@ -21,6 +21,24 @@ import {
2121 hasNoValues ,
2222} from './utils' ;
2323
24+ function isObjectReasonablyEqual ( foo , bar ) {
25+ if ( isNotDefined ( foo ) && isNotDefined ( bar ) ) {
26+ return true ;
27+ }
28+ if ( isNotDefined ( foo ) || isNotDefined ( bar ) ) {
29+ return false ;
30+ }
31+ const fooKeys = new Set ( Reflect . ownKeys ( foo ) . map ( ( key ) => isDefined ( foo [ key ] ) ? key : undefined ) . filter ( isDefined ) ) ;
32+ const barKeys = new Set ( Reflect . ownKeys ( bar ) . map ( ( key ) => isDefined ( bar [ key ] ) ? key : undefined ) . filter ( isDefined ) ) ;
33+ if ( fooKeys . size !== barKeys . size ) {
34+ return false ;
35+ }
36+ if ( [ ...fooKeys ] . some ( ( fooKey ) => ! barKeys . has ( fooKey ) ) ) {
37+ return false ;
38+ }
39+ return [ ...fooKeys ] . every ( ( fooKey ) => foo [ fooKey ] === bar [ fooKey ] ) ;
40+ }
41+
2442export function accumulateValues (
2543 obj ,
2644 schema ,
@@ -76,7 +94,7 @@ export function accumulateValues(
7694 }
7795 return schema . defaultValue ;
7896 }
79- // FIXME : should we instead use (return nullable ? null : undefined)?
97+ // TODO : should we instead use (return nullable ? null : undefined)?
8098 return [ ] ;
8199 }
82100 return values ;
@@ -216,7 +234,6 @@ export function accumulateErrors(
216234 return error ;
217235}
218236
219- // FIXME: only copy oldErrors when a change is detected
220237export function accumulateDifferentialErrors (
221238 oldObj ,
222239 newObj ,
@@ -246,7 +263,7 @@ export function accumulateDifferentialErrors(
246263 const isSchemaForObject = ! ! fields ;
247264
248265 if ( isSchemaForArray ) {
249- const errors = { } ;
266+ let errors = { } ;
250267 // FIXME: make this more performant? deps?
251268 if ( validation ) {
252269 const validationErrors = validation ( newObj , baseValue , context ) ;
@@ -279,8 +296,6 @@ export function accumulateDifferentialErrors(
279296 const localMember = member ( e . new ) ;
280297 const index = keySelector ( e . new ) ;
281298
282- // console.warn(index, depsChanged);
283-
284299 const fieldError = accumulateDifferentialErrors (
285300 e . old ,
286301 e . new ,
@@ -296,6 +311,9 @@ export function accumulateDifferentialErrors(
296311 }
297312 } ) ;
298313
314+ if ( isObjectReasonablyEqual ( oldError , errors ) ) {
315+ return oldError ;
316+ }
299317 return hasNoKeys ( errors ) ? undefined : errors ;
300318 }
301319
@@ -324,8 +342,6 @@ export function accumulateDifferentialErrors(
324342 || ( depsChanged && isDefined ( dependenciesObj ?. [ fieldName ] ) )
325343 ) ;
326344
327- // console.warn(fieldName, depsChangedForField, dependenciesObj?.[fieldName]);
328-
329345 const fieldError = accumulateDifferentialErrors (
330346 oldObj ?. [ fieldName ] ,
331347 newObj ?. [ fieldName ] ,
@@ -341,6 +357,9 @@ export function accumulateDifferentialErrors(
341357 }
342358 } ) ;
343359
360+ if ( isObjectReasonablyEqual ( oldError , errors ) ) {
361+ return oldError ;
362+ }
344363 return hasNoKeys ( errors ) ? undefined : errors ;
345364 }
346365
@@ -397,7 +416,7 @@ export function analyzeErrors(errors) {
397416}
398417
399418// FIXME: move this to a helper
400- // FIXME : check conditions for change in context and baseValue
419+ // TODO : check conditions for change in context and baseValue
401420export function addCondition (
402421 schema ,
403422 value ,
0 commit comments