The library for web and native user interfaces.
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.
Tim Yung committed
Jul 10, 2013 at 14:45 UTC
8687645c50b0211f60ded688d95fedd9735a37ee
1 file changed
+6
src/core/ReactCompositeComponent.js
+6
@@ -875,6 +875,12 @@ var ReactCompositeComponent = {
875
Constructor.prototype.render,
876
'createClass(...): Class specification must implement a `render` method.'
877
);
878
+ // Reduce time spent doing lookups by setting these on the prototype.
879
+ for (var methodName in ReactCompositeComponentInterface) {
880
+ if (!Constructor.prototype[methodName]) {
881
+ Constructor.prototype[methodName] = null;
882
+ }
883
+ }
884
885
var ConvenienceConstructor = function(props, children) {
886
var instance = new Constructor();