@samitouri / QOS-React / commits / b717db00fb

Add shouldComponentUpdate to functional components

I'll probably end up reverting this before the bigger release since it is not part of the official public API. However, it is useful to be able to compare the performance between functional components and classes.

Sebastian Markbage committed Sep 1, 2016 at 20:58 UTC b717db00fbea7a8f12dba360c37f81278988f139
1 file changed +10
src/renderers/shared/fiber/ReactFiberBeginWork.js
+10
@@ -72,6 +72,16 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
72 var fn = workInProgress.type;
73 var props = workInProgress.pendingProps;
74
75 + // TODO: Disable this before release, since it is not part of the public API
76 + // I use this for testing to compare the relative overhead of classes.
77 + if (typeof fn.shouldComponentUpdate === 'function') {
78 + if (workInProgress.memoizedProps !== null) {
79 + if (!fn.shouldComponentUpdate(workInProgress.memoizedProps, props)) {
80 + return bailoutOnAlreadyFinishedWork(current, workInProgress);
81 + }
82 + }
83 + }
84 +
85 var nextChildren = fn(props);
86 reconcileChildren(current, workInProgress, nextChildren);
87 return workInProgress.child;