Prefix internal context properties with underscore (#12358)
So these aren't mistaken for public properties. Ideally, we'd use symbols or private fields.
Andrew Clark committed
Mar 12, 2018 at 14:30 UTC
ad9544f48e58f2599a8ea0de1e9f4dd104db30bb
5 files changed
+26
-24
packages/react-dom/src/server/ReactPartialRenderer.js
+4
-4
@@ -675,7 +675,7 @@ class ReactDOMServerRenderer {
675
this.providerIndex += 1;
676
this.providerStack[this.providerIndex] = provider;
677
const context: ReactContext<any> = provider.type.context;
678
- context.currentValue = provider.props.value;
678
+ context._currentValue = provider.props.value;
679
}
680
681
popProvider<T>(provider: ReactProvider<T>): void {
@@ -690,13 +690,13 @@ class ReactDOMServerRenderer {
690
this.providerIndex -= 1;
691
const context: ReactContext<any> = provider.type.context;
692
if (this.providerIndex < 0) {
693
- context.currentValue = context.defaultValue;
693
+ context._currentValue = context._defaultValue;
694
} else {
695
// We assume this type is correct because of the index check above.
696
const previousProvider: ReactProvider<any> = (this.providerStack[
697
this.providerIndex
698
]: any);
699
- context.currentValue = previousProvider.props.value;
699
+ context._currentValue = previousProvider.props.value;
700
}
701
}
702
@@ -865,7 +865,7 @@ class ReactDOMServerRenderer {
865
case REACT_CONTEXT_TYPE: {
866
const consumer: ReactConsumer<any> = (nextChild: any);
867
const nextProps: any = consumer.props;
868
- const nextValue = consumer.type.currentValue;
868
+ const nextValue = consumer.type._currentValue;
869
870
const nextChildren = toArray(nextProps.children(nextValue));
871
const frame: Frame = {
packages/react-reconciler/src/ReactFiberBeginWork.js
+4
-4
@@ -893,8 +893,8 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
893
changedBits = 0;
894
} else {
895
changedBits =
896
- typeof context.calculateChangedBits === 'function'
897
- ? context.calculateChangedBits(oldValue, newValue)
896
+ typeof context._calculateChangedBits === 'function'
897
+ ? context._calculateChangedBits(oldValue, newValue)
898
: MAX_SIGNED_31_BIT_INT;
899
if (__DEV__) {
900
warning(
@@ -942,8 +942,8 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
942
const newProps = workInProgress.pendingProps;
943
const oldProps = workInProgress.memoizedProps;
944
945
- const newValue = context.currentValue;
946
- const changedBits = context.changedBits;
945
+ const newValue = context._currentValue;
946
+ const changedBits = context._changedBits;
947
948
if (hasLegacyContextChanged()) {
949
// Normally we can bail out on props equality but if context has changed
packages/react-reconciler/src/ReactFiberNewContext.js
+8
-8
@@ -26,11 +26,11 @@ if (__DEV__) {
26
export function pushProvider(providerFiber: Fiber): void {
27
const context: ReactContext<any> = providerFiber.type.context;
28
index += 1;
29
- changedBitsStack[index] = context.changedBits;
30
- currentValueStack[index] = context.currentValue;
29
+ changedBitsStack[index] = context._changedBits;
30
+ currentValueStack[index] = context._currentValue;
31
stack[index] = providerFiber;
32
- context.currentValue = providerFiber.pendingProps.value;
33
- context.changedBits = providerFiber.stateNode;
32
+ context._currentValue = providerFiber.pendingProps.value;
33
+ context._changedBits = providerFiber.stateNode;
34
35
if (__DEV__) {
36
warning(
@@ -54,16 +54,16 @@ export function popProvider(providerFiber: Fiber): void {
54
stack[index] = null;
55
index -= 1;
56
const context: ReactContext<any> = providerFiber.type.context;
57
- context.currentValue = currentValue;
58
- context.changedBits = changedBits;
57
+ context._currentValue = currentValue;
58
+ context._changedBits = changedBits;
59
}
60
61
export function resetProviderStack(): void {
62
for (let i = index; i > -1; i--) {
63
const providerFiber = stack[i];
64
const context: ReactContext<any> = providerFiber.type.context;
65
- context.currentValue = context.defaultValue;
66
- context.changedBits = 0;
65
+ context._currentValue = context._defaultValue;
66
+ context._changedBits = 0;
67
changedBitsStack[i] = null;
68
currentValueStack[i] = null;
69
stack[i] = null;
packages/react/src/ReactContext.js
+4
-4
@@ -33,10 +33,10 @@ export function createContext<T>(
33
34
const context: ReactContext<T> = {
35
$$typeof: REACT_CONTEXT_TYPE,
36
- calculateChangedBits,
37
- defaultValue,
38
- currentValue: defaultValue,
39
- changedBits: 0,
36
+ _calculateChangedBits: calculateChangedBits,
37
+ _defaultValue: defaultValue,
38
+ _currentValue: defaultValue,
39
+ _changedBits: 0,
40
// These are circular
41
Provider: (null: any),
42
Consumer: (null: any),
packages/shared/ReactTypes.js
+6
-4
@@ -80,10 +80,12 @@ export type ReactContext<T> = {
80
$$typeof: Symbol | number,
81
Consumer: ReactContext<T>,
82
Provider: ReactProviderType<T>,
83
- calculateChangedBits: ((a: T, b: T) => number) | null,
84
- defaultValue: T,
85
- currentValue: T,
86
- changedBits: number,
83
+
84
+ _calculateChangedBits: ((a: T, b: T) => number) | null,
85
+ _defaultValue: T,
86
+
87
+ _currentValue: T,
88
+ _changedBits: number,
89
90
// DEV only
91
_currentRenderer?: Object | null,