Skip to content

Commit ca09ef8

Browse files
committed
Converted did-warn objects to Sets in ReactFiberClassComponent
1 parent b09b5d2 commit ca09ef8

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/react-reconciler/src/ReactFiberClassComponent.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@ let didWarnAboutLegacyLifecyclesAndDerivedState;
4646
let warnOnInvalidCallback;
4747

4848
if (__DEV__) {
49-
didWarnAboutStateAssignmentForComponent = {};
50-
didWarnAboutUndefinedDerivedState = {};
51-
didWarnAboutUninitializedState = {};
49+
didWarnAboutStateAssignmentForComponent = new Set();
50+
didWarnAboutUndefinedDerivedState = new Set();
51+
didWarnAboutUninitializedState = new Set();
5252
didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
53-
didWarnAboutLegacyLifecyclesAndDerivedState = {};
53+
didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
5454

55-
const didWarnOnInvalidCallback = {};
55+
const didWarnOnInvalidCallback = new Set();
5656

5757
warnOnInvalidCallback = function(callback: mixed, callerName: string) {
5858
if (callback === null || typeof callback === 'function') {
5959
return;
6060
}
6161
const key = `${callerName}_${(callback: any)}`;
62-
if (!didWarnOnInvalidCallback[key]) {
62+
if (!didWarnOnInvalidCallback.has(key)) {
63+
didWarnOnInvalidCallback.add(key);
6364
warning(
6465
false,
6566
'%s(...): Expected the last optional `callback` argument to be a ' +
6667
'function. Instead received: %s.',
6768
callerName,
6869
callback,
6970
);
70-
didWarnOnInvalidCallback[key] = true;
7171
}
7272
};
7373

@@ -458,15 +458,15 @@ export default function(
458458
state === null
459459
) {
460460
const componentName = getComponentName(workInProgress) || 'Component';
461-
if (!didWarnAboutUninitializedState[componentName]) {
461+
if (!didWarnAboutUninitializedState.has(componentName)) {
462+
didWarnAboutUninitializedState.add(componentName);
462463
warning(
463464
false,
464465
'%s: Did not properly initialize state during construction. ' +
465466
'Expected state to be an object, but it was %s.',
466467
componentName,
467468
instance.state === null ? 'null' : 'undefined',
468469
);
469-
didWarnAboutUninitializedState[componentName] = true;
470470
}
471471
}
472472

@@ -514,7 +514,8 @@ export default function(
514514
typeof ctor.getDerivedStateFromProps === 'function'
515515
? 'getDerivedStateFromProps()'
516516
: 'getSnapshotBeforeUpdate()';
517-
if (!didWarnAboutLegacyLifecyclesAndDerivedState[componentName]) {
517+
if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(componentName)) {
518+
didWarnAboutLegacyLifecyclesAndDerivedState.add(componentName);
518519
warning(
519520
false,
520521
'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
@@ -529,7 +530,6 @@ export default function(
529530
: '',
530531
foundWillUpdateName !== null ? `\n ${foundWillUpdateName}` : '',
531532
);
532-
didWarnAboutLegacyLifecyclesAndDerivedState[componentName] = true;
533533
}
534534
}
535535
}
@@ -610,15 +610,15 @@ export default function(
610610
if (instance.state !== oldState) {
611611
if (__DEV__) {
612612
const componentName = getComponentName(workInProgress) || 'Component';
613-
if (!didWarnAboutStateAssignmentForComponent[componentName]) {
613+
if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
614+
didWarnAboutStateAssignmentForComponent.add(componentName);
614615
warning(
615616
false,
616617
'%s.componentWillReceiveProps(): Assigning directly to ' +
617618
"this.state is deprecated (except inside a component's " +
618619
'constructor). Use setState instead.',
619620
componentName,
620621
);
621-
didWarnAboutStateAssignmentForComponent[componentName] = true;
622622
}
623623
}
624624
updater.enqueueReplaceState(instance, instance.state, null);
@@ -652,14 +652,14 @@ export default function(
652652
if (__DEV__) {
653653
if (partialState === undefined) {
654654
const componentName = getComponentName(workInProgress) || 'Component';
655-
if (!didWarnAboutUndefinedDerivedState[componentName]) {
655+
if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
656+
didWarnAboutUndefinedDerivedState.add(componentName);
656657
warning(
657658
false,
658659
'%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' +
659660
'You have returned undefined.',
660661
componentName,
661662
);
662-
didWarnAboutUndefinedDerivedState[componentName] = componentName;
663663
}
664664
}
665665
}

0 commit comments

Comments
 (0)