@@ -21,6 +21,32 @@ 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 (
32+ Reflect . ownKeys ( foo )
33+ . map ( ( key ) => ( isDefined ( foo [ key ] ) ? key : undefined ) )
34+ . filter ( isDefined ) ,
35+ ) ;
36+ const barKeys = new Set (
37+ Reflect . ownKeys ( bar )
38+ . map ( ( key ) => ( isDefined ( bar [ key ] ) ? key : undefined ) )
39+ . filter ( isDefined ) ,
40+ ) ;
41+ if ( fooKeys . size !== barKeys . size ) {
42+ return false ;
43+ }
44+ if ( [ ...fooKeys ] . some ( ( fooKey ) => ! barKeys . has ( fooKey ) ) ) {
45+ return false ;
46+ }
47+ return [ ...fooKeys ] . every ( ( fooKey ) => foo [ fooKey ] === bar [ fooKey ] ) ;
48+ }
49+
2450export function accumulateValues (
2551 obj ,
2652 schema ,
@@ -76,7 +102,7 @@ export function accumulateValues(
76102 }
77103 return schema . defaultValue ;
78104 }
79- // FIXME : should we instead use (return nullable ? null : undefined)?
105+ // TODO : should we instead use (return nullable ? null : undefined)?
80106 return [ ] ;
81107 }
82108 return values ;
@@ -216,7 +242,6 @@ export function accumulateErrors(
216242 return error ;
217243}
218244
219- // FIXME: only copy oldErrors when a change is detected
220245export function accumulateDifferentialErrors (
221246 oldObj ,
222247 newObj ,
@@ -279,8 +304,6 @@ export function accumulateDifferentialErrors(
279304 const localMember = member ( e . new ) ;
280305 const index = keySelector ( e . new ) ;
281306
282- // console.warn(index, depsChanged);
283-
284307 const fieldError = accumulateDifferentialErrors (
285308 e . old ,
286309 e . new ,
@@ -296,6 +319,9 @@ export function accumulateDifferentialErrors(
296319 }
297320 } ) ;
298321
322+ if ( isObjectReasonablyEqual ( oldError , errors ) ) {
323+ return oldError ;
324+ }
299325 return hasNoKeys ( errors ) ? undefined : errors ;
300326 }
301327
@@ -324,8 +350,6 @@ export function accumulateDifferentialErrors(
324350 || ( depsChanged && isDefined ( dependenciesObj ?. [ fieldName ] ) )
325351 ) ;
326352
327- // console.warn(fieldName, depsChangedForField, dependenciesObj?.[fieldName]);
328-
329353 const fieldError = accumulateDifferentialErrors (
330354 oldObj ?. [ fieldName ] ,
331355 newObj ?. [ fieldName ] ,
@@ -341,6 +365,9 @@ export function accumulateDifferentialErrors(
341365 }
342366 } ) ;
343367
368+ if ( isObjectReasonablyEqual ( oldError , errors ) ) {
369+ return oldError ;
370+ }
344371 return hasNoKeys ( errors ) ? undefined : errors ;
345372 }
346373
@@ -397,7 +424,7 @@ export function analyzeErrors(errors) {
397424}
398425
399426// FIXME: move this to a helper
400- // FIXME : check conditions for change in context and baseValue
427+ // TODO : check conditions for change in context and baseValue
401428export function addCondition (
402429 schema ,
403430 value ,
0 commit comments