From 3ba5681cc0776007c9b2ce3308bdc885ace90f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Wed, 5 Oct 2022 13:35:33 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Tim Golen --- lib/fastMerge.js | 13 +++++-------- lib/storage/providers/LocalForage.js | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/fastMerge.js b/lib/fastMerge.js index 106712ea..a403f093 100644 --- a/lib/fastMerge.js +++ b/lib/fastMerge.js @@ -16,8 +16,6 @@ function isMergeableObject(val) { } /** - * Merge Object and Arrays - * * @param {{}|[]} target * @param {{}|[]} source * @returns {{}|[]} @@ -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]; diff --git a/lib/storage/providers/LocalForage.js b/lib/storage/providers/LocalForage.js index 5170d961..20d70795 100644 --- a/lib/storage/providers/LocalForage.js +++ b/lib/storage/providers/LocalForage.js @@ -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); });