Remove some invariants and deadcode
These are not necessary if we enable type checks. Static or dynamic. They're distracting my greppability. Also, some dead code in shallow rendering.
Sebastian Markbage committed
Nov 17, 2014 at 21:46 UTC
13ed0317fa4aeb2281dbd295b302d99ad2cd6aed
4 files changed
+5
-38
src/browser/ui/ReactDOMComponent.js
-5
@@ -172,7 +172,6 @@ ReactDOMComponent.Mixin = {
172
* @return {string} The computed markup.
173
*/
174
mountComponent: function(rootID, transaction, mountDepth, context) {
175
- invariant(context !== undefined, "Context is required parameter");
175
ReactComponent.Mixin.mountComponent.call(
176
this,
177
rootID,
@@ -287,7 +286,6 @@ ReactDOMComponent.Mixin = {
286
},
287
288
receiveComponent: function(nextElement, transaction, context) {
290
- invariant(context !== undefined, "Context is required parameter");
289
if (nextElement === this._currentElement &&
290
nextElement._owner != null) {
291
// Since elements are immutable after the owner is rendered,
@@ -316,8 +314,6 @@ ReactDOMComponent.Mixin = {
314
* @overridable
315
*/
316
updateComponent: function(transaction, prevElement, nextElement, context) {
319
- if(context === undefined) throw new Error("Context required for mounting");
320
- if(context === null) throw new Error("Assert: context is not null");
317
assertValidProps(this._currentElement.props);
318
ReactComponent.Mixin.updateComponent.call(
319
this,
@@ -435,7 +431,6 @@ ReactDOMComponent.Mixin = {
431
* @param {ReactReconcileTransaction} transaction
432
*/
433
_updateDOMChildren: function(lastProps, transaction, context) {
438
- invariant(context !== undefined, "Context is required parameter");
434
var nextProps = this._currentElement.props;
435
436
var lastContent =
src/core/ReactComponent.js
-2
@@ -108,7 +108,6 @@ var ReactComponent = {
108
* @internal
109
*/
110
mountComponent: function(rootID, transaction, mountDepth, context) {
111
- invariant(context !== undefined, "Context is required parameter");
111
var ref = this._currentElement.ref;
112
if (ref != null) {
113
var owner = this._currentElement._owner;
@@ -144,7 +143,6 @@ var ReactComponent = {
143
* @internal
144
*/
145
updateComponent: function(transaction, prevElement, nextElement, context) {
147
- invariant(context !== undefined, "Context is required parameter");
146
// If either the owner or a `ref` has changed, make sure the newest owner
147
// has stored a reference to `this`, and the previous owner (if different)
148
// has forgotten the reference to `this`. We use the element instead
src/core/ReactCompositeComponent.js
+5
-26
@@ -158,7 +158,6 @@ var ReactCompositeComponentMixin = assign({},
158
* @internal
159
*/
160
mountComponent: function(rootID, transaction, mountDepth, context) {
161
- invariant(context !== undefined, "Context is required parameter");
161
ReactComponent.Mixin.mountComponent.call(
162
this,
163
rootID,
@@ -520,7 +519,6 @@ var ReactCompositeComponentMixin = assign({},
519
},
520
521
receiveComponent: function(nextElement, transaction, context) {
523
- invariant(context !== undefined, "Context is required parameter");
522
if (nextElement === this._currentElement &&
523
nextElement._owner != null) {
524
// Since elements are immutable after the owner is rendered,
@@ -589,8 +587,6 @@ var ReactCompositeComponentMixin = assign({},
587
* TODO: Remove this check when owner-context is removed
588
*/
589
_warnIfContextsDiffer: function(ownerBasedContext, parentBasedContext) {
592
- invariant(ownerBasedContext !== undefined, "Owner based context is required parameter");
593
- invariant(parentBasedContext !== undefined, "Parent based ontext is required parameter");
590
var ownerKeys = Object.keys(ownerBasedContext).sort();
591
var parentKeys = Object.keys(parentBasedContext).sort();
592
if (ownerKeys.length != parentKeys.length || ownerKeys.toString() != parentKeys.toString()) {
@@ -720,8 +716,6 @@ var ReactCompositeComponentMixin = assign({},
716
transaction,
717
unmaskedContext
718
) {
723
- invariant(unmaskedContext !== undefined, "Context required for mounting");
724
- invariant(unmaskedContext !== null, "Context must be non-null");
719
var inst = this._instance;
720
721
var prevProps = inst.props;
@@ -755,7 +749,6 @@ var ReactCompositeComponentMixin = assign({},
749
* @internal
750
*/
751
_updateRenderedComponent: function(transaction, context) {
758
- invariant(context !== undefined, "Context is required parameter");
752
var prevComponentInstance = this._renderedComponent;
753
var prevRenderedElement = prevComponentInstance._currentElement;
754
var nextRenderedElement = this._renderValidatedComponent();
@@ -968,25 +961,11 @@ var ShallowMixin = assign({},
961
var prevComponentInstance = this._renderedComponent;
962
var prevRenderedElement = prevComponentInstance._currentElement;
963
// Use the without-owner-or-context variant of _rVC below:
971
- var nextRenderedElement = this._renderValidatedComponentWithoutOwnerOrContext();
972
- if (shouldUpdateReactComponent(prevRenderedElement, nextRenderedElement)) {
973
- prevComponentInstance.receiveComponent(
974
- nextRenderedElement,
975
- transaction
976
- );
977
- } else {
978
- // These two IDs are actually the same! But nothing should rely on that.
979
- var thisID = this._rootNodeID;
980
- var prevComponentID = prevComponentInstance._rootNodeID;
981
- // Don't unmount previous instance since it was never mounted, due to
982
- // shallow render.
983
- //prevComponentInstance.unmountComponent();
984
- this._renderedComponent = nextRenderedElement;
985
- // ^ no instantiateReactComponent
986
- //
987
- // no recursive mountComponent
988
- return nextRenderedElement;
989
- }
964
+ var nextRenderedElement =
965
+ this._renderValidatedComponentWithoutOwnerOrContext();
966
+ // This is a noop in shallow render
967
+ shouldUpdateReactComponent(prevRenderedElement, nextRenderedElement);
968
+ this._renderedComponent = nextRenderedElement;
969
}
970
971
});
src/core/ReactMultiChild.js
-5
@@ -17,7 +17,6 @@ var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes');
17
18
var flattenChildren = require('flattenChildren');
19
var instantiateReactComponent = require('instantiateReactComponent');
20
-var invariant = require('invariant');
20
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
21
22
/**
@@ -180,7 +179,6 @@ var ReactMultiChild = {
179
* @internal
180
*/
181
mountChildren: function(nestedChildren, transaction, context) {
183
- invariant(context !== undefined, "Context is required parameter");
182
var children = flattenChildren(nestedChildren);
183
var mountImages = [];
184
var index = 0;
@@ -244,7 +242,6 @@ var ReactMultiChild = {
242
* @internal
243
*/
244
updateChildren: function(nextNestedChildren, transaction, context) {
247
- invariant(context !== undefined, "Context is required parameter");
245
updateDepth++;
246
var errorThrown = true;
247
try {
@@ -268,7 +265,6 @@ var ReactMultiChild = {
265
* @protected
266
*/
267
_updateChildren: function(nextNestedChildren, transaction, context) {
271
- invariant(context !== undefined, "Context is required parameter");
268
var nextChildren = flattenChildren(nextNestedChildren);
269
var prevChildren = this._renderedChildren;
270
if (!nextChildren && !prevChildren) {
@@ -400,7 +396,6 @@ var ReactMultiChild = {
396
index,
397
transaction,
398
context) {
403
- invariant(context !== undefined, "Context is required parameter");
399
// Inlined for performance, see `ReactInstanceHandles.createReactID`.
400
var rootID = this._rootNodeID + name;
401
var mountImage = child.mountComponent(