Reduce Lookup for Missing Lifecycle Methods

This is a micro-optimization that reduces the lookup time for missing lifecycle methods. The extra amount of memory is linear to the number of components that exist on a page which I think is a worthwile trade-off.
This commit is contained in:
Tim Yung
2013-07-10 15:04:44 -07:00
committed by Paul O’Shannessy
parent 7b68fcd408
commit 8687645c50
+6
View File
@@ -875,6 +875,12 @@ var ReactCompositeComponent = {
Constructor.prototype.render,
'createClass(...): Class specification must implement a `render` method.'
);
// Reduce time spent doing lookups by setting these on the prototype.
for (var methodName in ReactCompositeComponentInterface) {
if (!Constructor.prototype[methodName]) {
Constructor.prototype[methodName] = null;
}
}
var ConvenienceConstructor = function(props, children) {
var instance = new Constructor();