Add nextContext to componentWillReceiveProps

Add `nextContext` as an argument to `componentWillReceiveProps`. We can figure out what to rename the method to later.
This commit is contained in:
Tim Yung
2013-11-20 14:19:01 -08:00
committed by Paul O’Shannessy
parent a23d43bf05
commit 04c3e2e407
2 changed files with 13 additions and 6 deletions
+6 -6
View File
@@ -202,7 +202,7 @@ var ReactCompositeComponentInterface = {
* Use this as an opportunity to react to a prop transition by updating the
* state using `this.setState`. Current props are accessed via `this.props`.
*
* componentWillReceiveProps: function(nextProps) {
* componentWillReceiveProps: function(nextProps, nextContext) {
* this.setState({
* likesIncreasing: nextProps.likeCount > this.props.likeCount
* });
@@ -823,6 +823,10 @@ var ReactCompositeComponentMixin = {
return;
}
var nextFullContext = this._pendingContext || this._currentContext;
var nextContext = this._processContext(nextFullContext);
this._pendingContext = null;
var nextProps = this.props;
if (this._pendingProps != null) {
nextProps = this._pendingProps;
@@ -831,7 +835,7 @@ var ReactCompositeComponentMixin = {
this._compositeLifeCycleState = CompositeLifeCycle.RECEIVING_PROPS;
if (this.componentWillReceiveProps) {
this.componentWillReceiveProps(nextProps);
this.componentWillReceiveProps(nextProps, nextContext);
}
}
@@ -840,10 +844,6 @@ var ReactCompositeComponentMixin = {
var nextState = this._pendingState || this.state;
this._pendingState = null;
var nextFullContext = this._pendingContext || this._currentContext;
var nextContext = this._processContext(nextFullContext);
this._pendingContext = null;
if (this._pendingForceUpdate ||
!this.shouldComponentUpdate ||
this.shouldComponentUpdate(nextProps, nextState, nextContext)) {
@@ -639,6 +639,7 @@ describe('ReactCompositeComponent', function() {
});
it('should filter context properly in callbacks', function() {
var actualComponentWillReceiveProps;
var actualShouldComponentUpdate;
var actualComponentWillUpdate;
var actualComponentDidUpdate;
@@ -666,6 +667,11 @@ describe('ReactCompositeComponent', function() {
foo: ReactPropTypes.string
},
componentWillReceiveProps: function(nextProps, nextContext) {
actualComponentWillReceiveProps = nextContext;
return true;
},
shouldComponentUpdate: function(nextProps, nextState, nextContext) {
actualShouldComponentUpdate = nextContext;
return true;
@@ -687,6 +693,7 @@ describe('ReactCompositeComponent', function() {
var instance = <Parent foo="abc" />;
ReactTestUtils.renderIntoDocument(instance);
instance.replaceProps({foo: "def"});
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
expect(actualComponentWillUpdate).toEqual({foo: 'def'});
expect(actualComponentDidUpdate).toEqual({foo: 'abc'});