Move _pendingX into ReactCompositeComponent
Since setProps can no longer be called on anything but composites, we can move this complexity into ReactCompositeComponent.
Sebastian Markbage committed
Nov 17, 2014 at 00:48 UTC
bc4dd411b06b3ae22f16ec622c6f2ca8de44bf6b
3 files changed
+12
-49
src/browser/ui/ReactDOMComponent.js
+3
-5
@@ -291,11 +291,9 @@ ReactDOMComponent.Mixin = {
291
return;
292
}
293
294
- ReactComponent.Mixin.receiveComponent.call(
295
- this,
296
- nextElement,
297
- transaction
298
- );
294
+ var prevElement = this._currentElement;
295
+ this._currentElement = nextElement;
296
+ this.updateComponent(transaction, prevElement, nextElement);
297
},
298
299
/**
src/core/ReactComponent.js
-39
@@ -115,13 +115,9 @@ var ReactComponent = {
115
* @internal
116
*/
117
construct: function(element) {
118
- // See ReactUpdates.
119
- this._pendingCallbacks = null;
120
-
118
// We keep the old element and a reference to the pending element
119
// to track updates.
120
this._currentElement = element;
124
- this._pendingElement = null;
121
},
122
123
/**
@@ -167,41 +163,6 @@ var ReactComponent = {
163
unmountIDFromEnvironment(this._rootNodeID);
164
// Reset all fields
165
this._rootNodeID = null;
170
- this._pendingCallbacks = null;
171
- this._pendingElement = null;
172
- },
173
-
174
- /**
175
- * Given a new instance of this component, updates the rendered DOM nodes
176
- * as if that instance was rendered instead.
177
- *
178
- * Subclasses that override this method should make sure to invoke
179
- * `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
180
- *
181
- * @param {object} nextComponent Next set of properties.
182
- * @param {ReactReconcileTransaction} transaction
183
- * @internal
184
- */
185
- receiveComponent: function(nextElement, transaction) {
186
- this._pendingElement = nextElement;
187
- this.performUpdateIfNecessary(transaction);
188
- },
189
-
190
- /**
191
- * If `_pendingElement` is set, update the component.
192
- *
193
- * @param {ReactReconcileTransaction} transaction
194
- * @internal
195
- */
196
- performUpdateIfNecessary: function(transaction) {
197
- if (this._pendingElement == null) {
198
- return;
199
- }
200
- var prevElement = this._currentElement;
201
- var nextElement = this._pendingElement;
202
- this._currentElement = nextElement;
203
- this._pendingElement = null;
204
- this.updateComponent(transaction, prevElement, nextElement);
166
},
167
168
/**
src/core/ReactCompositeComponent.js
+9
-5
@@ -115,11 +115,15 @@ var ReactCompositeComponentMixin = assign({},
115
this._instance.context = null;
116
this._instance.refs = emptyObject;
117
118
+ this._pendingElement = null;
119
this._pendingState = null;
120
this._compositeLifeCycleState = null;
121
122
// Children can be either an array or more than one argument
123
ReactComponent.Mixin.construct.apply(this, arguments);
124
+
125
+ // See ReactUpdates.
126
+ this._pendingCallbacks = null;
127
},
128
129
/**
@@ -234,6 +238,9 @@ var ReactCompositeComponentMixin = assign({},
238
// Reset pending fields
239
this._pendingState = null;
240
this._pendingForceUpdate = false;
241
+ this._pendingCallbacks = null;
242
+ this._pendingElement = null;
243
+
244
ReactComponent.Mixin.unmountComponent.call(this);
245
246
// Delete the reference from the instance to this internal representation
@@ -505,11 +512,8 @@ var ReactCompositeComponentMixin = assign({},
512
return;
513
}
514
508
- ReactComponent.Mixin.receiveComponent.call(
509
- this,
510
- nextElement,
511
- transaction
512
- );
515
+ this._pendingElement = nextElement;
516
+ this.performUpdateIfNecessary(transaction);
517
},
518
519
/**