Refactor ensureUpdateQueues to avoid returning a tuple (#10437)
* remove tuple * clean up * prettier code * Use module-level varibles
zombieJ committed
Aug 29, 2017 at 02:04 UTC
c282a8ef4f10b071a56514bebaf1447c9bda1ddf
1 file changed
+12
-9
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+12
-9
@@ -68,6 +68,9 @@ export type UpdateQueue = {
68
isProcessing?: boolean,
69
};
70
71
+let _queue1;
72
+let _queue2;
73
+
74
function comparePriority(a: PriorityLevel, b: PriorityLevel): number {
75
// When comparing update priorities, treat sync and Task work as equal.
76
// TODO: Could we avoid the need for this by always coercing sync priority
@@ -160,7 +163,7 @@ function findInsertionPosition(queue, update): Update | null {
163
return insertAfter;
164
}
165
163
-function ensureUpdateQueues(fiber: Fiber): [UpdateQueue, UpdateQueue | null] {
166
+function ensureUpdateQueues(fiber: Fiber) {
167
const alternateFiber = fiber.alternate;
168
169
let queue1 = fiber.updateQueue;
@@ -178,12 +181,9 @@ function ensureUpdateQueues(fiber: Fiber): [UpdateQueue, UpdateQueue | null] {
181
queue2 = null;
182
}
183
181
- // TODO: Refactor to avoid returning a tuple.
182
- return [
183
- queue1,
184
- // Return null if there is no alternate queue, or if its queue is the same.
185
- queue2 !== queue1 ? queue2 : null,
186
- ];
184
+ _queue1 = queue1;
185
+ // Return null if there is no alternate queue, or if its queue is the same.
186
+ _queue2 = queue2 !== queue1 ? queue2 : null;
187
}
188
189
// The work-in-progress queue is a subset of the current queue (if it exists).
@@ -217,7 +217,9 @@ function ensureUpdateQueues(fiber: Fiber): [UpdateQueue, UpdateQueue | null] {
217
// If the update is cloned, it returns the cloned update.
218
function insertUpdate(fiber: Fiber, update: Update): Update | null {
219
// We'll have at least one and at most two distinct update queues.
220
- const [queue1, queue2] = ensureUpdateQueues(fiber);
220
+ ensureUpdateQueues(fiber);
221
+ const queue1 = _queue1;
222
+ const queue2 = _queue2;
223
224
// Warn if an update is scheduled from inside an updater function.
225
if (__DEV__) {
@@ -370,7 +372,8 @@ function addTopLevelUpdate(
372
if (isTopLevelUnmount) {
373
// TODO: Redesign the top-level mount/update/unmount API to avoid this
374
// special case.
373
- const [queue1, queue2] = ensureUpdateQueues(fiber);
375
+ const queue1 = _queue1;
376
+ const queue2 = _queue2;
377
378
// Drop all updates that are lower-priority, so that the tree is not
379
// remounted. We need to do this for both queues.