Skip to content

Commit

Permalink
Remove lodash (#2916)
Browse files Browse the repository at this point in the history
## Description

Since `lodash` is used only in one place in our codebase, we can simply replace it with our own implementation on `deepEqual`.

Closes #2613 

## Test plan

Run example apps.
---------

Co-authored-by: Jakub Piasecki <[email protected]>
  • Loading branch information
m-bert and j-piasecki authored May 17, 2024
1 parent 4c906f9 commit 00dcb64
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"@egjs/hammerjs": "^2.0.17",
"hoist-non-react-statics": "^3.3.0",
"invariant": "^2.2.4",
"lodash": "^4.17.21",
"prop-types": "^15.7.2"
},
"jest": {
Expand Down
4 changes: 1 addition & 3 deletions src/handlers/createHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
EmitterSubscription,
} from 'react-native';
import { customDirectEventTypes } from './customDirectEventTypes';
// @ts-ignore - it isn't typed by TS & don't have definitelyTyped types
import deepEqual from 'lodash/isEqual';
import RNGestureHandlerModule from '../RNGestureHandlerModule';
import { State } from '../State';
import {
Expand All @@ -25,7 +23,7 @@ import {
scheduleFlushOperations,
} from './gestureHandlerCommon';
import { ValueOf } from '../typeUtils';
import { isFabric, isJestEnv, tagMessage } from '../utils';
import { deepEqual, isFabric, isJestEnv, tagMessage } from '../utils';
import { ActionType } from '../ActionType';
import { PressabilityDebugView } from './PressabilityDebugView';
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext';
Expand Down
39 changes: 39 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,42 @@ export function isRemoteDebuggingEnabled(): boolean {
!localGlobal.RN$Bridgeless
);
}

/**
* Recursively compares two objects for deep equality.
*
* **Note:** This function does not support cyclic references.
*
* @param obj1 - The first object to compare.
* @param obj2 - The second object to compare.
* @returns `true` if the objects are deeply equal, `false` otherwise.
*/
export function deepEqual(obj1: any, obj2: any) {
if (obj1 === obj2) {
return true;
}

if (
typeof obj1 !== 'object' ||
typeof obj2 !== 'object' ||
obj1 === null ||
obj2 === null
) {
return false;
}

const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);

if (keys1.length !== keys2.length) {
return false;
}

for (const key of keys1) {
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
return false;
}
}

return true;
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9046,7 +9046,7 @@ [email protected]:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"

lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.5.0, lodash@^4.6.0, lodash@^4.6.1, lodash@^4.7.0:
lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.5.0, lodash@^4.6.0, lodash@^4.6.1, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down

0 comments on commit 00dcb64

Please sign in to comment.