Skip to content

Commit

Permalink
Reduce Lookup for Missing Lifecycle Methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yungsters authored and zpao committed Jul 10, 2013
1 parent 7b68fcd commit 8687645
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8687645

Please sign in to comment.