diff --git a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts index 5732cb93f19c..4c18e161c9a9 100644 --- a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts +++ b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts @@ -3,20 +3,9 @@ import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRo import getTopmostFullScreenRoute from '@libs/Navigation/getTopmostFullScreenRoute'; import type {Metainfo} from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types'; +import shallowCompare from '@libs/ObjectUtils'; import NAVIGATORS from '@src/NAVIGATORS'; -// eslint-disable-next-line @typescript-eslint/ban-types -const shallowCompare = (obj1?: object, obj2?: object) => { - if (!obj1 && !obj2) { - return true; - } - if (obj1 && obj2) { - // @ts-expect-error we know that obj1 and obj2 are params of a route. - return Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every((key) => obj1[key] === obj2[key]); - } - return false; -}; - type GetPartialStateDiffReturnType = { [NAVIGATORS.BOTTOM_TAB_NAVIGATOR]?: NavigationPartialRoute; [NAVIGATORS.CENTRAL_PANE_NAVIGATOR]?: NavigationPartialRoute; diff --git a/src/libs/Navigation/linkTo.ts b/src/libs/Navigation/linkTo.ts index 630a44fe1d3b..863cb102add4 100644 --- a/src/libs/Navigation/linkTo.ts +++ b/src/libs/Navigation/linkTo.ts @@ -2,6 +2,7 @@ import {getActionFromState} from '@react-navigation/core'; import type {NavigationAction, NavigationContainerRef, NavigationState, PartialState} from '@react-navigation/native'; import type {Writable} from 'type-fest'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; +import shallowCompare from '@libs/ObjectUtils'; import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -30,18 +31,6 @@ type ActionPayload = { params?: ActionPayloadParams; }; -// eslint-disable-next-line @typescript-eslint/ban-types -const shallowCompare = (obj1?: object, obj2?: object) => { - if (!obj1 && !obj2) { - return true; - } - if (obj1 && obj2) { - // @ts-expect-error we know that obj1 and obj2 are params of a route. - return Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every((key) => obj1[key] === obj2[key]); - } - return false; -}; - /** * Motivation for this function is described in NAVIGATION.md * diff --git a/src/libs/ObjectUtils.ts b/src/libs/ObjectUtils.ts new file mode 100644 index 000000000000..9ffa461506c8 --- /dev/null +++ b/src/libs/ObjectUtils.ts @@ -0,0 +1,13 @@ +// eslint-disable-next-line @typescript-eslint/ban-types +const shallowCompare = (obj1?: object, obj2?: object) => { + if (!obj1 && !obj2) { + return true; + } + if (obj1 && obj2) { + // @ts-expect-error we know that obj1 and obj2 are params of a route. + return Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every((key) => obj1[key] === obj2[key]); + } + return false; +}; + +export default shallowCompare;