Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Golen <tgolen@gmail.com>
  • Loading branch information
Szymon20000 and tgolen committed Oct 5, 2022
1 parent 3e6cf77 commit 3ba5681
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/fastMerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ function isMergeableObject(val) {
}

/**
* Merge Object and Arrays
*
* @param {{}|[]} target
* @param {{}|[]} source
* @returns {{}|[]}
Expand All @@ -32,17 +30,16 @@ function fastMerge(target, source) {
}

/**
* Merge Object
*
* @param {{}} target
* @param {{}} source
* @returns {{}}
* @param {Object} target
* @param {Object} source
* @returns {Object}
*/
mergeObject = function (target, source) {
const destination = {};
if (isMergeableObject(target)) {
// lodash adds a small overhead so we don't use it here
// eslint-disable-next-line rulesdir/prefer-underscore-method
const targetKeys = Object.keys(target); // lodash adds a small overhead so we don't use it here
const targetKeys = Object.keys(target);
for (let i = 0; i < targetKeys.length; ++i) {
const key = targetKeys[i];
destination[key] = target[key];
Expand Down
3 changes: 2 additions & 1 deletion lib/storage/providers/LocalForage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const provider = {
return localforage.getItem(key)
.then((existingValue) => {
const newValue = _.isObject(existingValue)
// lodash adds a small overhead so we don't use it here
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
? Object.assign({}, fastMerge(existingValue, value)) // lodash adds a small overhead so we don't use it here
? Object.assign({}, fastMerge(existingValue, value))
: value;
return localforage.setItem(key, newValue);
});
Expand Down

0 comments on commit 3ba5681

Please sign in to comment.