Move _pendingX into ReactCompositeComponent

Since setProps can no longer be called on anything but composites, we can
move this complexity into ReactCompositeComponent.
This commit is contained in:
Sebastian Markbage
2014-11-17 12:54:21 -08:00
parent 974a4c84ce
commit bc4dd411b0
3 changed files with 12 additions and 49 deletions
+3 -5
View File
@@ -291,11 +291,9 @@ ReactDOMComponent.Mixin = {
return;
}
ReactComponent.Mixin.receiveComponent.call(
this,
nextElement,
transaction
);
var prevElement = this._currentElement;
this._currentElement = nextElement;
this.updateComponent(transaction, prevElement, nextElement);
},
/**
-39
View File
@@ -115,13 +115,9 @@ var ReactComponent = {
* @internal
*/
construct: function(element) {
// See ReactUpdates.
this._pendingCallbacks = null;
// We keep the old element and a reference to the pending element
// to track updates.
this._currentElement = element;
this._pendingElement = null;
},
/**
@@ -167,41 +163,6 @@ var ReactComponent = {
unmountIDFromEnvironment(this._rootNodeID);
// Reset all fields
this._rootNodeID = null;
this._pendingCallbacks = null;
this._pendingElement = null;
},
/**
* Given a new instance of this component, updates the rendered DOM nodes
* as if that instance was rendered instead.
*
* Subclasses that override this method should make sure to invoke
* `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
*
* @param {object} nextComponent Next set of properties.
* @param {ReactReconcileTransaction} transaction
* @internal
*/
receiveComponent: function(nextElement, transaction) {
this._pendingElement = nextElement;
this.performUpdateIfNecessary(transaction);
},
/**
* If `_pendingElement` is set, update the component.
*
* @param {ReactReconcileTransaction} transaction
* @internal
*/
performUpdateIfNecessary: function(transaction) {
if (this._pendingElement == null) {
return;
}
var prevElement = this._currentElement;
var nextElement = this._pendingElement;
this._currentElement = nextElement;
this._pendingElement = null;
this.updateComponent(transaction, prevElement, nextElement);
},
/**
+9 -5
View File
@@ -115,11 +115,15 @@ var ReactCompositeComponentMixin = assign({},
this._instance.context = null;
this._instance.refs = emptyObject;
this._pendingElement = null;
this._pendingState = null;
this._compositeLifeCycleState = null;
// Children can be either an array or more than one argument
ReactComponent.Mixin.construct.apply(this, arguments);
// See ReactUpdates.
this._pendingCallbacks = null;
},
/**
@@ -234,6 +238,9 @@ var ReactCompositeComponentMixin = assign({},
// Reset pending fields
this._pendingState = null;
this._pendingForceUpdate = false;
this._pendingCallbacks = null;
this._pendingElement = null;
ReactComponent.Mixin.unmountComponent.call(this);
// Delete the reference from the instance to this internal representation
@@ -505,11 +512,8 @@ var ReactCompositeComponentMixin = assign({},
return;
}
ReactComponent.Mixin.receiveComponent.call(
this,
nextElement,
transaction
);
this._pendingElement = nextElement;
this.performUpdateIfNecessary(transaction);
},
/**