Skip to content

Commit d278b8f

Browse files
author
Jack Pope
committed
Rename compare->select
1 parent 0f64b02 commit d278b8f

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
REACT_CONTEXT_TYPE,
3838
} from 'shared/ReactSymbols';
3939
import hasOwnProperty from 'shared/hasOwnProperty';
40-
import type {ContextDependencyWithCompare} from '../../react-reconciler/src/ReactInternalTypes';
40+
import type {ContextDependencyWithSelect} from '../../react-reconciler/src/ReactInternalTypes';
4141

4242
type CurrentDispatcherRef = typeof ReactSharedInternals;
4343

@@ -159,7 +159,7 @@ let currentHook: null | Hook = null;
159159
let currentContextDependency:
160160
| null
161161
| ContextDependency<mixed>
162-
| ContextDependencyWithCompare<mixed, mixed> = null;
162+
| ContextDependencyWithSelect<mixed> = null;
163163

164164
function nextHook(): null | Hook {
165165
const hook = currentHook;

packages/react-reconciler/src/ReactFiberNewContext.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
Fiber,
1313
ContextDependency,
1414
Dependencies,
15-
ContextDependencyWithCompare,
15+
ContextDependencyWithSelect,
1616
} from './ReactInternalTypes';
1717
import type {StackCursor} from './ReactFiberStack';
1818
import type {Lanes} from './ReactFiberLane';
@@ -75,7 +75,7 @@ if (__DEV__) {
7575
let currentlyRenderingFiber: Fiber | null = null;
7676
let lastContextDependency:
7777
| ContextDependency<mixed>
78-
| ContextDependencyWithCompare<mixed, mixed>
78+
| ContextDependencyWithSelect<mixed>
7979
| null = null;
8080
let lastFullyObservedContext: ReactContext<any> | null = null;
8181

@@ -408,15 +408,15 @@ function propagateContextChanges<T>(
408408
// Check if the context matches.
409409
if (dependency.context === context) {
410410
if (enableContextProfiling) {
411-
const compare = dependency.compare;
412-
if (compare != null && dependency.lastComparedValue != null) {
411+
const select = dependency.select;
412+
if (select != null && dependency.lastSelectedValue != null) {
413413
const newValue = isPrimaryRenderer
414414
? dependency.context._currentValue
415415
: dependency.context._currentValue2;
416416
if (
417-
!checkIfComparedContextValuesChanged(
418-
dependency.lastComparedValue,
419-
compare(newValue),
417+
!checkIfSelectedContextValuesChanged(
418+
dependency.lastSelectedValue,
419+
select(newValue),
420420
)
421421
) {
422422
// Compared value hasn't changed. Bail out early.
@@ -663,7 +663,7 @@ function propagateParentContextChanges(
663663
workInProgress.flags |= DidPropagateContext;
664664
}
665665

666-
function checkIfComparedContextValuesChanged(
666+
function checkIfSelectedContextValuesChanged(
667667
oldComparedValue: Array<mixed>,
668668
newComparedValue: Array<mixed>,
669669
): boolean {
@@ -706,13 +706,13 @@ export function checkIfContextChanged(
706706
const oldValue = dependency.memoizedValue;
707707
if (
708708
enableContextProfiling &&
709-
dependency.compare != null &&
710-
dependency.lastComparedValue != null
709+
dependency.select != null &&
710+
dependency.lastSelectedValue != null
711711
) {
712712
if (
713-
checkIfComparedContextValuesChanged(
714-
dependency.lastComparedValue,
715-
dependency.compare(newValue),
713+
checkIfSelectedContextValuesChanged(
714+
dependency.lastSelectedValue,
715+
dependency.select(newValue),
716716
)
717717
) {
718718
return true;
@@ -762,7 +762,7 @@ export function readContextAndCompare<C>(
762762
throw new Error('Not implemented.');
763763
}
764764

765-
return readContextForConsumer_withCompare(
765+
return readContextForConsumer_withSelect(
766766
currentlyRenderingFiber,
767767
context,
768768
compare,
@@ -796,10 +796,10 @@ export function readContextDuringReconciliation<T>(
796796
return readContextForConsumer(consumer, context);
797797
}
798798

799-
function readContextForConsumer_withCompare<C, S>(
799+
function readContextForConsumer_withSelect<C>(
800800
consumer: Fiber | null,
801801
context: ReactContext<C>,
802-
compare: C => Array<mixed>,
802+
select: C => Array<mixed>,
803803
): C {
804804
const value = isPrimaryRenderer
805805
? context._currentValue
@@ -812,8 +812,8 @@ function readContextForConsumer_withCompare<C, S>(
812812
context: ((context: any): ReactContext<mixed>),
813813
memoizedValue: value,
814814
next: null,
815-
compare: ((compare: any): (context: mixed) => Array<mixed>),
816-
lastComparedValue: compare(value),
815+
select: ((select: any): (context: mixed) => Array<mixed>),
816+
lastSelectedValue: select(value),
817817
};
818818

819819
if (lastContextDependency === null) {

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,23 @@ export type HookType =
6363

6464
export type ContextDependency<C> = {
6565
context: ReactContext<C>,
66-
next:
67-
| ContextDependency<mixed>
68-
| ContextDependencyWithCompare<mixed, mixed>
69-
| null,
66+
next: ContextDependency<mixed> | ContextDependencyWithSelect<mixed> | null,
7067
memoizedValue: C,
7168
};
7269

73-
export type ContextDependencyWithCompare<C, S> = {
70+
export type ContextDependencyWithSelect<C> = {
7471
context: ReactContext<C>,
75-
next:
76-
| ContextDependency<mixed>
77-
| ContextDependencyWithCompare<mixed, mixed>
78-
| null,
72+
next: ContextDependency<mixed> | ContextDependencyWithSelect<mixed> | null,
7973
memoizedValue: C,
80-
compare: C => Array<mixed>,
81-
lastComparedValue: ?Array<mixed>,
74+
select: C => Array<mixed>,
75+
lastSelectedValue: ?Array<mixed>,
8276
};
8377

8478
export type Dependencies = {
8579
lanes: Lanes,
8680
firstContext:
8781
| ContextDependency<mixed>
88-
| ContextDependencyWithCompare<mixed, mixed>
82+
| ContextDependencyWithSelect<mixed>
8983
| null,
9084
...
9185
};
@@ -402,7 +396,7 @@ export type Dispatcher = {
402396
): [S, Dispatch<A>],
403397
unstable_useContextWithBailout?: <T>(
404398
context: ReactContext<T>,
405-
compare: (T => Array<mixed>) | null,
399+
select: (T => Array<mixed>) | null,
406400
) => T,
407401
useContext<T>(context: ReactContext<T>): T,
408402
useRef<T>(initialValue: T): {current: T},

scripts/error-codes/codes.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,6 @@
525525
"537": "Cannot pass event handlers (%s) in renderToMarkup because the HTML will never be hydrated so they can never get called.",
526526
"538": "Cannot use state or effect Hooks in renderToMarkup because this component will never be hydrated.",
527527
"539": "Binary RSC chunks cannot be encoded as strings. This is a bug in the wiring of the React streams.",
528-
"540": "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams."
529-
}
528+
"540": "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams.",
529+
"541": "Compared context values must be arrays"
530+
}

0 commit comments

Comments
 (0)