Skip to content

Commit

Permalink
Merge pull request #1288 from KidkArolis/remove-lodash
Browse files Browse the repository at this point in the history
Replace lodash/merge with a very simple deep merge
  • Loading branch information
theKashey authored Jul 6, 2019
2 parents be4ed21 + 5185464 commit 2f8b933
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/reconciler/proxies.js
Original file line number Diff line number Diff line change
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
22 changes: 22 additions & 0 deletions src/reconciler/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,25 @@ 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 (const entry of Object.entries(source)) {
const key = entry[0];
let value = entry[1];
if (value instanceof Object && key in acc) {
value = merge(acc[key], value);
}
acc = { ...acc, [key]: value };
}
}
}
return acc;
}

0 comments on commit 2f8b933

Please sign in to comment.