|
25 | 25 | } = require('ReactFiberUpdateQueue');
|
26 | 26 | var { isMounted } = require('ReactFiberTreeReflection');
|
27 | 27 | var ReactInstanceMap = require('ReactInstanceMap');
|
| 28 | +var shallowEqual = require('shallowEqual'); |
28 | 29 |
|
29 | 30 | module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : PriorityLevel) => void) {
|
30 | 31 |
|
@@ -73,6 +74,28 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
|
73 | 74 | },
|
74 | 75 | };
|
75 | 76 |
|
| 77 | + function checkShouldComponentUpdate(workInProgress, oldProps, newProps, newState) { |
| 78 | + const updateQueue = workInProgress.updateQueue; |
| 79 | + if (oldProps === null || updateQueue && updateQueue.isForced)) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + |
| 83 | + const instance = workInProgress.stateNode; |
| 84 | + if (typeof instance.shouldComponentUpdate === 'function') { |
| 85 | + return instance.shouldComponentUpdate(newProps, newState); |
| 86 | + } |
| 87 | + |
| 88 | + const type = workInProgress.type; |
| 89 | + if (type.prototype && type.prototype.isPureReactComponent) { |
| 90 | + return ( |
| 91 | + !shallowEqual(oldProps, newProps) || |
| 92 | + !shallowEqual(instance.state, newState) |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + return true; |
| 97 | + } |
| 98 | + |
76 | 99 | function adoptClassInstance(workInProgress : Fiber, instance : any) : void {
|
77 | 100 | instance.updater = updater;
|
78 | 101 | workInProgress.stateNode = instance;
|
@@ -132,13 +155,12 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
|
132 | 155 | // componentWillMount and before this componentWillMount? Probably
|
133 | 156 | // unsupported anyway.
|
134 | 157 |
|
135 |
| - const updateQueue = workInProgress.updateQueue; |
136 |
| - |
137 |
| - // If this completed, we might be able to just reuse this instance. |
138 |
| - if (typeof instance.shouldComponentUpdate === 'function' && |
139 |
| - !(updateQueue && updateQueue.isForced) && |
140 |
| - workInProgress.memoizedProps !== null && |
141 |
| - !instance.shouldComponentUpdate(newProps, newState)) { |
| 158 | + if (!checkShouldComponentUpdate( |
| 159 | + workInProgress, |
| 160 | + workInProgress.memoizedProps, |
| 161 | + newProps, |
| 162 | + newState |
| 163 | + )) { |
142 | 164 | return false;
|
143 | 165 | }
|
144 | 166 |
|
@@ -196,10 +218,12 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
|
196 | 218 | newState = previousState;
|
197 | 219 | }
|
198 | 220 |
|
199 |
| - if (typeof instance.shouldComponentUpdate === 'function' && |
200 |
| - !(updateQueue && updateQueue.isForced) && |
201 |
| - oldProps !== null && |
202 |
| - !instance.shouldComponentUpdate(newProps, newState)) { |
| 221 | + if (!checkShouldComponentUpdate( |
| 222 | + workInProgress, |
| 223 | + oldProps, |
| 224 | + newProps, |
| 225 | + newState |
| 226 | + )) { |
203 | 227 | // TODO: Should this get the new props/state updated regardless?
|
204 | 228 | return false;
|
205 | 229 | }
|
|
0 commit comments