Skip to content

remove deep-assign dependency #392

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
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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
"react": "^16.8",
"react-native": ">=0.59"
},
"dependencies": {
"deep-assign": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
Expand Down
13 changes: 11 additions & 2 deletions src/AsyncStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
* @flow
*/

import merge from 'deep-assign';
const merge = (target = {}, source = {}) => {
Copy link
Member

@krizzu krizzu Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is our own implementation, could you export this function (and write a comment that it's being exported for tests only) and write some tests? To make sure this works as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had started working on the requested changes but it looks like there is already an own, native implementation of deep merge in the code:

Can this code be moved into main file? What is the best approach in this situation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I forgot about that code there 😊 But this should not be a problem in that case - the _deepMerge function is used in Mock function. What I meant in my request was to write tests for merge function only, to check if it properly merges objects together.

I guess we could try to reuse merge in mock itself, but I'm not sure if that's good approach - the mock has no external (or even internal) dependencies, and I'd like to keep it that way

Copy link
Contributor Author

@Simek Simek Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little bit afraid that I don't fully understand your test plan or your testing approach. I happy to help with fixing the initial issue and the basic tests but don't want to spend a lot of time working on the full test suite for this change.

So there are three options I consider:

  • ditching both native implementations (in code and in mock) in favor of one of recommended replace packages (this would not require creating test suite, but this still will require avoidable dependency),
  • leaving native merge as is and include/copy tests from the deep-merge package,
  • closing this PR as is right now with an offer to help when someone decide to tackle this issue again in the future.

Let me know what's your opinion about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with changing the dependency to something else (more tested and used), than having own implementation, so that we save time on writing proper implementation and tests.

for (const key of Object.keys(source)) {
if (source[key] instanceof Object) {
Object.assign(source[key], merge(target[key], source[key]));
} else {
source[key] = target[key] || source[key];
}
}
return Object.assign(target, source);
};

const mergeLocalStorageItem = (key, value) => {
const oldValue = window.localStorage.getItem(key);
const oldObject = JSON.parse(oldValue);
const newObject = JSON.parse(value);
const nextValue = JSON.stringify(merge({}, oldObject, newObject));
const nextValue = JSON.stringify(merge(oldObject, newObject));
window.localStorage.setItem(key, nextValue);
};

Expand Down