dillon1000/react
Commit
Browse files Preparing to 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 of abstracting it out since this is just an intermediate step to avoid spamming consoles. This makes more a much cleaner diff review/history. The original validation in the instance will be deleted as soon as we can turn on the warnings. 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 will later be 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.
Changed paths7 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__/ReactCompositeComponent-test.js ModifiedM src/core/__tests__/ReactPropTransferer-test.js ModifiedM src/core/__tests__/ReactPropTypes-test.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…