import { isPlainObject as _iPO } from '@reduxjs/toolkit' ; const isPlainObject = _iPO ; export function copyWithStructuralSharing < T > ( oldObj , newObj ) ; export function copyWithStructuralSharing ( oldObj , newObj ) { if ( oldObj === newObj || ! ( ( isPlainObject ( oldObj ) && isPlainObject ( newObj ) ) || ( Array . isArray ( oldObj ) && Array . isArray ( newObj ) ) ) ) { return newObj ; } const newKeys = Object . keys ( newObj ) ; const oldKeys = Object . keys ( oldObj ) ; let isSameObject = newKeys . length === oldKeys . length ; const mergeObj = Array . isArray ( newObj ) ? [ ] : { } ; for ( const key of newKeys ) { mergeObj [ key ] = copyWithStructuralSharing ( oldObj [ key ] , newObj [ key ] ) ; if ( isSameObject ) isSameObject = oldObj [ key ] === mergeObj [ key ] ; } return isSameObject ? oldObj : mergeObj ; }