@samitouri / QOS-React-2 / commits / cb1ef03df9

Replace .hasForceUpdate with ForceUpdate effect

Removes another field from the update queue

Andrew Clark committed Dec 9, 2016 at 12:47 UTC cb1ef03df9019a8235dd1a12539068f030fb48a9
5 files changed +22 -26
src/renderers/shared/fiber/ReactFiberBeginWork.js
-2
@@ -493,8 +493,6 @@ module.exports = function<T, P, I, TI, C, CX>(
493 const memoizedProps = workInProgress.memoizedProps;
494 const updateQueue = workInProgress.updateQueue;
495
496 -
497 -
496 // This is kept as a single expression to take advantage of short-circuiting.
497 const hasNewProps = (
498 pendingProps !== null && ( // hasPendingProps && (
src/renderers/shared/fiber/ReactFiberClassComponent.js
+5 -4
@@ -26,6 +26,8 @@ var {
26 addCallback,
27 beginUpdateQueue,
28 } = require('ReactFiberUpdateQueue');
29 +var { hasContextChanged } = require('ReactFiberContext');
30 +var { ForceUpdate } = require('ReactTypeOfSideEffect');
31 var { getComponentName, isMounted } = require('ReactFiberTreeReflection');
32 var ReactInstanceMap = require('ReactInstanceMap');
33 var shallowEqual = require('shallowEqual');
@@ -76,8 +78,7 @@ module.exports = function(scheduleUpdate : (fiber: Fiber) => void) {
78 };
79
80 function checkShouldComponentUpdate(workInProgress, oldProps, newProps, newState, newContext) {
79 - const updateQueue = workInProgress.updateQueue;
80 - if (oldProps === null || (updateQueue && updateQueue.hasForceUpdate)) {
81 + if (oldProps === null || (workInProgress.effectTag & ForceUpdate)) {
82 // If the workInProgress already has an Update effect, return true
83 return true;
84 }
@@ -339,8 +340,8 @@ module.exports = function(scheduleUpdate : (fiber: Fiber) => void) {
340
341 if (oldProps === newProps &&
342 oldState === newState &&
342 - oldContext === newContext &&
343 - updateQueue && !updateQueue.hasForceUpdate) {
343 + !hasContextChanged() &&
344 + !(workInProgress.effectTag & ForceUpdate)) {
345 return false;
346 }
347
src/renderers/shared/fiber/ReactFiberScheduler.js
+3 -1
@@ -40,6 +40,7 @@ var {
40 Placement,
41 Update,
42 PlacementAndUpdate,
43 + ForceUpdate,
44 Deletion,
45 ContentReset,
46 Callback,
@@ -199,7 +200,8 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
200 // updates, and deletions. To avoid needing to add a case for every
201 // possible bitmap value, we remove the secondary effects from the
202 // effect tag and switch on that value.
202 - let primaryEffectTag = nextEffect.effectTag & ~(Callback | Err | ContentReset);
203 + let primaryEffectTag =
204 + nextEffect.effectTag & ~(ForceUpdate | Callback | Err | ContentReset);
205 switch (primaryEffectTag) {
206 case Placement: {
207 commitPlacement(nextEffect);
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+4 -10
@@ -15,6 +15,7 @@
15 import type { Fiber } from 'ReactFiber';
16
17 const {
18 + ForceUpdate,
19 Callback: CallbackEffect,
20 } = require('ReactTypeOfSideEffect');
21
@@ -41,11 +42,6 @@ export type UpdateQueue = {
42 firstPendingUpdate: Update | null,
43 // Points to the last (newest) update.
44 last: Update | null,
44 -
45 - // Used to implement forceUpdate. Only true if there's a merged (non-pending)
46 - // force update; pending force updates do not affect this.
47 - // TODO: We could use a ForceUpdate effect instead?
48 - hasForceUpdate: boolean,
45 };
46
47 exports.createUpdateQueue = function() : UpdateQueue {
@@ -53,8 +49,6 @@ exports.createUpdateQueue = function() : UpdateQueue {
49 first: null,
50 firstPendingUpdate: null,
51 last: null,
56 -
57 - hasForceUpdate: false,
52 };
53 };
54
@@ -184,8 +178,8 @@ exports.beginUpdateQueue = function(workInProgress : Fiber, queue : UpdateQueue,
178 // TODO: Would memoization be worth it?
179
180 // Reset these flags. We'll update them while looping through the queue.
187 - queue.hasForceUpdate = false;
188 - workInProgress.effectTag |= CallbackEffect;
181 + workInProgress.effectTag &= ~ForceUpdate;
182 + workInProgress.effectTag &= ~CallbackEffect;
183
184 let state = prevState;
185 let dontMutatePrevState = true;
@@ -215,7 +209,7 @@ exports.beginUpdateQueue = function(workInProgress : Fiber, queue : UpdateQueue,
209 }
210 }
211 if (update.isForced) {
218 - queue.hasForceUpdate = true;
212 + workInProgress.effectTag |= ForceUpdate;
213 }
214 if (update.callback) {
215 workInProgress.effectTag |= CallbackEffect;
src/renderers/shared/fiber/ReactTypeOfSideEffect.js
+10 -9
@@ -12,15 +12,16 @@
12
13 'use strict';
14
15 -export type TypeOfSideEffect = 0 | 1 | 2 | 3 | 4 | 8 | 16 | 32;
15 +export type TypeOfSideEffect = 0 | 1 | 2 | 3 | 4 | 8 | 16 | 32 | 64;
16
17 module.exports = {
18 - NoEffect: 0, // 0b000000
19 - Placement: 1, // 0b000001
20 - Update: 2, // 0b000010
21 - PlacementAndUpdate: 3, // 0b000011
22 - Deletion: 4, // 0b000100
23 - ContentReset: 8, // 0b001000
24 - Callback: 16, // 0b010000
25 - Err: 32, // 0b100000
18 + NoEffect: 0, // 0b0000000
19 + Placement: 1, // 0b0000001
20 + Update: 2, // 0b0000010
21 + PlacementAndUpdate: 3, // 0b0000011
22 + ForceUpdate: 4, // 0b0000100
23 + Deletion: 8, // 0b0001000
24 + ContentReset: 16, // 0b0010000
25 + Callback: 32, // 0b0100000
26 + Err: 64, // 0b1000000
27 };