1- import { Argument , AllArguments } from " ./Arguments" ;
1+ import { Argument , AllArguments } from ' ./Arguments' ;
22import { GetPropertyState } from './states/GetPropertyState' ;
33import { InitialState } from './states/InitialState' ;
44import { Context } from './Context' ;
@@ -21,6 +21,7 @@ export enum SubstituteMethods {
2121 rejects = 'rejects'
2222}
2323
24+ const seenObject = Symbol ( ) ;
2425export const Nothing = Symbol ( ) ;
2526export type Nothing = typeof Nothing
2627
@@ -73,27 +74,31 @@ export function areArgumentsEqual(a: any, b: any) {
7374 return deepEqual ( a , b ) ;
7475} ;
7576
76- function deepEqual ( a : any , b : any ) : boolean {
77- if ( Array . isArray ( a ) ) {
78- if ( ! Array . isArray ( b ) || a . length !== b . length ) return false ;
79- for ( let i = 0 ; i < a . length ; i ++ ) {
80- if ( ! deepEqual ( a [ i ] , b [ i ] ) ) return false ;
81- }
82- return true ;
83- }
84- if ( typeof a === 'object' && a !== null && b !== null ) {
85- if ( ! ( typeof b === 'object' ) ) return false ;
77+ function deepEqual ( realA : any , realB : any , objectReferences : Object [ ] = [ ] ) : boolean {
78+ const a = objectReferences . includes ( realA ) ? seenObject : realA ;
79+ const b = objectReferences . includes ( realB ) ? seenObject : realB ;
80+ const newObjectReferences = updateObjectReferences ( objectReferences , a , b ) ;
81+
82+ if ( nonNullObject ( a ) && nonNullObject ( b ) ) {
8683 if ( a . constructor !== b . constructor ) return false ;
87- const keys = Object . keys ( a ) ;
88- if ( keys . length !== Object . keys ( b ) . length ) return false ;
84+ if ( Object . keys ( a ) . length !== Object . keys ( b ) . length ) return false ;
8985 for ( const key in a ) {
90- if ( ! deepEqual ( a [ key ] , b [ key ] ) ) return false ;
86+ if ( ! deepEqual ( a [ key ] , b [ key ] , newObjectReferences ) ) return false ;
9187 }
9288 return true ;
9389 }
9490 return a === b ;
9591}
9692
93+ function updateObjectReferences ( objectReferences : Array < Object > , a : any , b : any ) {
94+ const tempObjectReferences = [ ...objectReferences , nonNullObject ( a ) && ! objectReferences . includes ( a ) ? a : void 0 ] ;
95+ return [ ...tempObjectReferences , nonNullObject ( b ) && ! tempObjectReferences . includes ( b ) ? b : void 0 ] ;
96+ }
97+
98+ function nonNullObject ( value : any ) {
99+ return typeof value === 'object' && value !== null ;
100+ }
101+
97102export function Get ( recorder : InitialState , context : Context , property : PropertyKey ) {
98103 const existingGetState = recorder . getPropertyStates . find ( state => state . property === property ) ;
99104 if ( existingGetState ) {
0 commit comments