From 98c93d62a3bac9d73d6e9247c240bcd089affab9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Feb 2019 00:05:08 -0800 Subject: [PATCH] [Refactor] `utils`: reduce observable [[Get]]s --- lib/utils.js | 5 +++-- test/utils.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index cfed4ecd..b9b18cd3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -76,8 +76,9 @@ var merge = function merge(target, source, options) { if (Array.isArray(target) && Array.isArray(source)) { source.forEach(function (item, i) { if (has.call(target, i)) { - if (target[i] && typeof target[i] === 'object' && item && typeof item === 'object') { - target[i] = merge(target[i], item, options); + var targetItem = target[i]; + if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') { + target[i] = merge(targetItem, item, options); } else { target.push(item); } diff --git a/test/utils.js b/test/utils.js index fcd85a01..c3faa704 100644 --- a/test/utils.js +++ b/test/utils.js @@ -39,10 +39,10 @@ test('merge()', function (t) { }); utils.merge(observed, [null]); st.equal(setCount, 0); - st.equal(getCount, 2); + st.equal(getCount, 1); observed[0] = observed[0]; // eslint-disable-line no-self-assign st.equal(setCount, 1); - st.equal(getCount, 3); + st.equal(getCount, 2); st.end(); } );