Skip to content

Commit

Permalink
Warns when muted props are passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Oct 31, 2015
1 parent 7619214 commit 17104f0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/renderers/shared/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ var ReactCompositeComponentMixin = {
// Initialize the public class
var inst;
var renderedElement;
var propsMuted = false;

// This is a way to detect if Component is a stateless arrow function
// component, which is not newable. It might not be 100% reliable but is
Expand Down Expand Up @@ -195,6 +196,32 @@ var ReactCompositeComponentMixin = {
Component.displayName || Component.name || 'Component'
);
}

propsMuted = (function(instProps, pubProps) {
var instPropsKeys, pubPropsKeys, arePropsMuted, prop, i, ii;
instPropsKeys = Object.keys(instProps || {});
pubPropsKeys = Object.keys(pubProps);
arePropsMuted = false;
if (instPropsKeys.length !== pubPropsKeys.length) {
arePropsMuted = true;
}
for (i = 0, ii = instPropsKeys.length; i < ii; i += 1) {
prop = instPropsKeys[i];
if (instProps[prop] !== pubProps[prop]) {
arePropsMuted = true;
break;
}
}
return arePropsMuted;
}(inst.props, publicProps));

if (!propsMuted) {
warning(
!propsMuted,
'Muted props not allowed in %s(...)',
Component.displayName || Component.name || 'Component'
);
}
}

// These should be set up in the constructor, but as a convenience for
Expand Down

0 comments on commit 17104f0

Please sign in to comment.