1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function mergeProps(obj, newObj) {
|
10 | if (newObj == undefined) {
|
11 | return newObj;
|
12 | }
|
13 |
|
14 | if (typeof obj === 'undefined' ||
|
15 | !Object.getPrototypeOf(obj).isPrototypeOf(newObj) ||
|
16 | (newObj.constructor.name !== 'Object' && newObj.constructor.name !== 'Array')) {
|
17 | return newObj;
|
18 | }
|
19 | var clone = {};
|
20 | Object.keys(newObj).forEach(function (key) {
|
21 | var exists = obj.hasOwnProperty(key);
|
22 | if (!exists) {
|
23 | clone[key] = newObj[key];
|
24 | }
|
25 | else {
|
26 | if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
27 | clone[key] = mergeProps(obj[key], newObj[key]);
|
28 | }
|
29 | else {
|
30 | clone[key] = newObj[key];
|
31 | }
|
32 | }
|
33 | });
|
34 |
|
35 | Object.keys(obj).forEach(function (key) {
|
36 | var exists = newObj.hasOwnProperty(key);
|
37 | if (!exists) {
|
38 | clone[key] = obj[key];
|
39 | }
|
40 | });
|
41 |
|
42 | Object.setPrototypeOf(clone, Object.getPrototypeOf(obj));
|
43 | return clone;
|
44 | }
|
45 | exports.default = mergeProps;
|