dillon1000/react
Commit
Browse files Move defaultProps resolution and type validation to the descriptor
This copies the propType and contextType validation to a wrapper around the descriptor factory. By doing the validation early, we make it easier to track down bugs. It also prepares for static type checking which should be done at the usage site. This validation is not yet active and is just logged using monitorCodeUse. This will allow us to clean up callsites which would fail this new type of validation. I chose to copy the validation instead of abstracting it out to a common abstraction. This is just an intermediate step to avoid spamming consoles. The original validation in the instance will be deleted as soon as we can turn on the warnings at the callsite. Copy+Delete makes this a more a much cleaner diff review/history. Additionally, getDefaultProps are moved to become a static function which is only executed once. It should be moved to statics but we don't have a convenient way to merge mixins in statics right now. Deferring to ES6 classes. This is still a breaking change since you can return an object or array from getDefaultProps, which later gets mutated and now the shared instance is mutated. Mutating an object that is passed into you from props is highly discouraged and likely to lead to subtle bugs anyway. So I'm not too worried. The defaultProps are now resolved in the descriptor factory. This will enable a perf optimizations where we don't create an unnecessary object allocation when you use default props. It also means that ReactChildren.map has access to resolved properties which gives them consistent behavior whether or not the default prop is specified. This is a breaking change since it can affect how mapping over children and transferPropsTo works together with defaultProps.
Changed paths5 files
First-parent comparisonsrc/browser/ReactDOM.js ModifiedM src/core/ReactCompositeComponent.js ModifiedM src/core/ReactDescriptor.js ModifiedA src/core/ReactDescriptorValidator.js AddedM src/core/__tests__/ReactPropTypes-test.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…