Update shallowCompare to accept nextContext (#6661)

* Update shallowCompare to accept nextContext

Across our application we are using immutable objects as properties and thus using shallowCompare for all our {{shouldComponentUpdate}}.  Because of this children with contextTypes don't get updates when the context on the parent changes.  Adding an additional comparison for context (when it is provided) fixes this problem.

* Remove the undefined check

* Add nextContext
This commit is contained in:
Tony Rossi authored and Jim committed 2016-05-17 16:50:23 -07:00
1 parent 7f08961604
commit 8ea1cf4ee0
2 files changed
+5 -4

No files matched your search

@@ -40,8 +40,8 @@ var shallowCompare = require('shallowCompare');
* See https://facebook.github.io/react/docs/pure-render-mixin.html
*/
var ReactComponentWithPureRenderMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
shouldComponentUpdate: function(nextProps, nextState, nextContext) {
return shallowCompare(this, nextProps, nextState, nextContext);
},
};
+3 -2
View File
@@ -18,10 +18,11 @@ var shallowEqual = require('shallowEqual');
* See ReactComponentWithPureRenderMixin
* See also https://facebook.github.io/react/docs/shallow-compare.html
*/
function shallowCompare(instance, nextProps, nextState) {
function shallowCompare(instance, nextProps, nextState, nextContext) {
return (
!shallowEqual(instance.props, nextProps) ||
!shallowEqual(instance.state, nextState)
!shallowEqual(instance.state, nextState) ||
!shallowEqual(instance.context, nextContext)
);
}