Skip to content

Commit

Permalink
[Refactor] utils: reduce observable [[Get]]s
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 3, 2019
1 parent 49ad67f commit 98c93d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);
Expand Down

0 comments on commit 98c93d6

Please sign in to comment.