Skip to content

Commit

Permalink
Rewrite Components.set
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed May 9, 2019
1 parent ba02e10 commit 756a54c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,24 @@ class Components {
* @param {Object} props Additional properties to add to the component.
*/
set(node, props) {
while (node && !this._list[getId(node)]) {
let component;
while (!(component = this._list[getId(node)])) {
node = node.parent;
if (!node) {
return;
}
}
if (!node) {
return;
}
const id = getId(node);
let copyUsedPropTypes;
if (this._list[id]) {
// usedPropTypes is an array. _extend replaces existing array with a new one which caused issue #1309.
// preserving original array so it can be merged later on.
copyUsedPropTypes = this._list[id].usedPropTypes && this._list[id].usedPropTypes.slice();
}
this._list[id] = Object.assign(this._list[id], props);
if (this._list[id] && props.usedPropTypes) {
this._list[id].usedPropTypes = mergeUsedPropTypes(copyUsedPropTypes || [], props.usedPropTypes);
}

Object.assign(
component,
props,
{
usedPropTypes: mergeUsedPropTypes(
component.usedPropTypes || [],
props.usedPropTypes || []
)
}
);
}

/**
Expand Down

0 comments on commit 756a54c

Please sign in to comment.