Skip to content

fix: replace deprecated deep-assign with lodash merge #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"trailingComma": "all",
"bracketSpacing": false,
"jsxBracketSameLine": true,
"parser": "flow"
}
"parser": "flow",
"endOfLine": "auto"
}
23 changes: 3 additions & 20 deletions jest/async-storage-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @format
*/

import merge from 'lodash.merge';

const asMock = {
__INTERNAL_MOCK_STORAGE__: {},

Expand Down Expand Up @@ -95,31 +97,12 @@ async function _multiMerge(keyValuePairs, callback) {
const oldValue = JSON.parse(asMock.__INTERNAL_MOCK_STORAGE__[key]);

asMock.__INTERNAL_MOCK_STORAGE__[key] = JSON.stringify(
_deepMergeInto(oldValue, value),
merge(oldValue, value),
);
});

callback && callback(null);
return null;
}

const _isObject = (obj) => typeof obj === 'object' && !Array.isArray(obj);
const _deepMergeInto = (oldObject, newObject) => {
const newKeys = Object.keys(newObject);
const mergedObject = oldObject;

newKeys.forEach((key) => {
const oldValue = mergedObject[key];
const newValue = newObject[key];

if (_isObject(oldValue) && _isObject(newValue)) {
mergedObject[key] = _deepMergeInto(oldValue, newValue);
} else {
mergedObject[key] = newValue;
}
});

return mergedObject;
};

module.exports = asMock;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"test:e2e:macos": "scripts/macos_e2e.sh 'test'"
},
"dependencies": {
"deep-assign": "^3.0.0"
"lodash.merge": "^4.6.2"
},
"peerDependencies": {
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || ^0.64.0 || 1000.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @flow
*/

import merge from 'deep-assign';
import merge from 'lodash.merge';

const mergeLocalStorageItem = (key, value) => {
const oldValue = window.localStorage.getItem(key);
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9745,6 +9745,11 @@ lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.merge@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
Expand Down Expand Up @@ -15436,8 +15441,10 @@ watchpack@^1.6.1:
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453"
integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ==
dependencies:
chokidar "^3.4.1"
graceful-fs "^4.1.2"
neo-async "^2.5.0"
watchpack-chokidar2 "^2.0.1"
optionalDependencies:
chokidar "^3.4.1"
watchpack-chokidar2 "^2.0.1"
Expand Down