Skip to content

Commit aba46cb

Browse files
committed
Enhance the extend function
1 parent 8fe46f0 commit aba46cb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/index.jsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ const getModelItems = (wrapperComponent) => {
2929
};
3030

3131
const extend = (target, ...sources) => {
32-
sources.forEach((source) => {
33-
for (let key in source) {
34-
if (source.hasOwnProperty(key)) {
35-
target[key] = source[key];
32+
if (target === undefined || target === null) {
33+
throw new TypeError('Cannot convert undefined or null to object');
34+
}
35+
36+
const output = Object(target);
37+
for (let index = 0; index < sources.length; index++) {
38+
const source = sources[index];
39+
if (source !== undefined && source !== null) {
40+
for (let key in source) {
41+
if (source.hasOwnProperty(key)) {
42+
output[key] = source[key];
43+
}
3644
}
3745
}
38-
});
39-
40-
return target;
46+
}
47+
return output;
4148
};
4249

4350
const SortableMixin = (options = defaultOptions) => (Component) => class extends React.Component {

0 commit comments

Comments
 (0)