Skip to content

Commit

Permalink
Replace lodash/merge with a very simple deep merge
Browse files Browse the repository at this point in the history
  • Loading branch information
KidkArolis committed Jul 6, 2019
1 parent 19824db commit 2afc643
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/reconciler/proxies.js
Expand Up @@ -3,8 +3,7 @@ import { resetClassProxies } from '../proxy/createClassProxy';
import { isCompositeComponent, isReactClass } from '../internal/reactUtils';
import configuration from '../configuration';
import { incrementHotGeneration } from '../global/generation';

const merge = require('lodash/merge');
import { merge } from './utils';

let signatures;
let proxiesByID;
Expand Down
20 changes: 20 additions & 0 deletions src/reconciler/utils.js
Expand Up @@ -74,3 +74,23 @@ export const areSwappable = (a, b) => {
}
return false;
};

export function merge(...sources) {
let acc = {};
for (const source of sources) {
if (source instanceof Array) {
if (!(acc instanceof Array)) {
acc = [];
}
acc = [...acc, ...source];
} else if (source instanceof Object) {
for (let [key, value] of Object.entries(source)) {
if (value instanceof Object && key in acc) {
value = merge(acc[key], value);
}
acc = { ...acc, [key]: value };
}
}
}
return acc;
}

0 comments on commit 2afc643

Please sign in to comment.