@samitouri / QOS-React-2 / commits / 8ea1cf4ee0

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

Tony Rossi committed May 17, 2016 at 19:50 UTC 8ea1cf4ee0f5315c4190a9e67e15f0f7404cb0cf
2 files changed +5 -4
src/addons/ReactComponentWithPureRenderMixin.js
+2 -2
@@ -40,8 +40,8 @@ var shallowCompare = require('shallowCompare');
40 * See https://facebook.github.io/react/docs/pure-render-mixin.html
41 */
42 var ReactComponentWithPureRenderMixin = {
43 - shouldComponentUpdate: function(nextProps, nextState) {
44 - return shallowCompare(this, nextProps, nextState);
43 + shouldComponentUpdate: function(nextProps, nextState, nextContext) {
44 + return shallowCompare(this, nextProps, nextState, nextContext);
45 },
46 };
47
src/addons/shallowCompare.js
+3 -2
@@ -18,10 +18,11 @@ var shallowEqual = require('shallowEqual');
18 * See ReactComponentWithPureRenderMixin
19 * See also https://facebook.github.io/react/docs/shallow-compare.html
20 */
21 -function shallowCompare(instance, nextProps, nextState) {
21 +function shallowCompare(instance, nextProps, nextState, nextContext) {
22 return (
23 !shallowEqual(instance.props, nextProps) ||
24 - !shallowEqual(instance.state, nextState)
24 + !shallowEqual(instance.state, nextState) ||
25 + !shallowEqual(instance.context, nextContext)
26 );
27 }
28