Skip to content

Commit 7f41ad5

Browse files
committed
Switch over primary effect types only
This avoids the need to create an export for every combination of bits.
1 parent 41ab7e8 commit 7f41ad5

File tree

2 files changed

+13
-47
lines changed

2 files changed

+13
-47
lines changed

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,7 @@ var {
4141
PlacementAndUpdate,
4242
Deletion,
4343
Callback,
44-
PlacementAndCallback,
45-
UpdateAndCallback,
46-
PlacementAndUpdateAndCallback,
47-
DeletionAndCallback,
4844
Err,
49-
PlacementAndErr,
50-
UpdateAndErr,
51-
PlacementAndUpdateAndErr,
52-
DeletionAndErr,
53-
PlacementAndCallbackAndErr,
54-
UpdateAndCallbackAndErr,
55-
PlacementAndUpdateAndCallbackAndErr,
56-
DeletionAndCallbackAndErr,
5745
} = require('ReactTypeOfSideEffect');
5846

5947
var {
@@ -173,44 +161,37 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
173161
// ref unmounts.
174162
let effectfulFiber = finishedWork.firstEffect;
175163
while (effectfulFiber) {
176-
switch (effectfulFiber.effectTag) {
177-
case Placement:
178-
case PlacementAndCallback:
179-
case PlacementAndErr:
180-
case PlacementAndCallbackAndErr: {
164+
// The following switch statement is only concerned about placement,
165+
// updates, and deletions. To avoid needing to add a case for every
166+
// possible bitmap value, we remove the secondary effects from the
167+
// effect tag and switch on that value.
168+
let primaryEffectTag = effectfulFiber.effectTag & ~(Callback | Err);
169+
switch (primaryEffectTag) {
170+
case Placement: {
181171
commitInsertion(effectfulFiber);
182172
// Clear the "placement" from effect tag so that we know that this is inserted, before
183173
// any life-cycles like componentDidMount gets called.
184-
effectfulFiber.effectTag ^= Placement;
174+
effectfulFiber.effectTag &= ~Placement;
185175
break;
186176
}
187-
case PlacementAndUpdate:
188-
case PlacementAndUpdateAndCallback:
189-
case PlacementAndUpdateAndErr:
190-
case PlacementAndUpdateAndCallbackAndErr: {
177+
case PlacementAndUpdate: {
191178
// Placement
192179
commitInsertion(effectfulFiber);
193180
// Clear the "placement" from effect tag so that we know that this is inserted, before
194181
// any life-cycles like componentDidMount gets called.
195-
effectfulFiber.effectTag ^= Placement;
182+
effectfulFiber.effectTag &= ~Placement;
196183

197184
// Update
198185
const current = effectfulFiber.alternate;
199186
commitWork(current, effectfulFiber);
200187
break;
201188
}
202-
case Update:
203-
case UpdateAndErr:
204-
case UpdateAndCallback:
205-
case UpdateAndCallbackAndErr: {
189+
case Update: {
206190
const current = effectfulFiber.alternate;
207191
commitWork(current, effectfulFiber);
208192
break;
209193
}
210-
case Deletion:
211-
case DeletionAndCallback:
212-
case DeletionAndErr:
213-
case DeletionAndCallbackAndErr: {
194+
case Deletion: {
214195
commitDeletion(effectfulFiber);
215196
break;
216197
}

src/renderers/shared/fiber/ReactTypeOfSideEffect.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
'use strict';
1414

15-
export type TypeOfSideEffect =
16-
0 | 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 24 | 25 |
17-
26 | 27 | 28;
15+
export type TypeOfSideEffect = 0 | 1 | 2 | 3 | 4 | 8 | 16;
1816

1917
module.exports = {
2018
NoEffect: 0, // 0b00000
@@ -23,18 +21,5 @@ module.exports = {
2321
PlacementAndUpdate: 3, // 0b00011
2422
Deletion: 4, // 0b00100
2523
Callback: 8, // 0b01000
26-
PlacementAndCallback: 9, // 0b01001
27-
UpdateAndCallback: 10, // 0b01010
28-
PlacementAndUpdateAndCallback: 11, // 0b01011
29-
DeletionAndCallback: 12, // 0b01100
3024
Err: 16, // 0b10000
31-
PlacementAndErr: 17, // 0b10001
32-
UpdateAndErr: 18, // 0b10010
33-
PlacementAndUpdateAndErr: 19, // 0b10011
34-
DeletionAndErr: 20, // 0b10100
35-
CallbackAndErr: 24, // 0b11000
36-
PlacementAndCallbackAndErr: 25, // 0b11001
37-
UpdateAndCallbackAndErr: 26, // 0b11010
38-
PlacementAndUpdateAndCallbackAndErr: 27, // 0b11011
39-
DeletionAndCallbackAndErr: 28, // 0b11100
4025
};

0 commit comments

Comments
 (0)