Skip to content

Commit 6b69938

Browse files
committed
Removes optimistic use of state.
1 parent 18f5f0c commit 6b69938

1 file changed

Lines changed: 32 additions & 24 deletions

File tree

src/redux.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,15 @@ export default function rootReducer(
421421
// (and a getState cascade) into this dispatch and trip the
422422
// "getState() while reducer is executing" guard. Defer to a
423423
// microtask so the dispatch fully unwinds before the callback fires.
424-
const callback = state.instructionsKeyCallback!;
425-
queueMicrotask(() =>
426-
callback(
427-
action.userUploadedData ? 'uploadedDataset' : 'selectedDataset',
428-
null,
429-
),
430-
);
424+
if (state.instructionsKeyCallback) {
425+
const callback = state.instructionsKeyCallback;
426+
queueMicrotask(() =>
427+
callback(
428+
action.userUploadedData ? 'uploadedDataset' : 'selectedDataset',
429+
null,
430+
),
431+
);
432+
}
431433
}
432434

433435
return {
@@ -685,8 +687,10 @@ export default function rootReducer(
685687
// If column is selected, then deselect.
686688
if (state.currentPanel === 'dataDisplayFeatures') {
687689
// Deferred — see SET_IMPORTED_DATA comment.
688-
const callback = state.instructionsKeyCallback!;
689-
queueMicrotask(() => callback('dataDisplayFeatures', null));
690+
if (state.instructionsKeyCallback) {
691+
const callback = state.instructionsKeyCallback;
692+
queueMicrotask(() => callback('dataDisplayFeatures', null));
693+
}
690694
}
691695
return {
692696
...state,
@@ -695,17 +699,19 @@ export default function rootReducer(
695699
} else {
696700
if (state.currentPanel === 'dataDisplayFeatures') {
697701
// Deferred — see SET_IMPORTED_DATA comment.
698-
const callback = state.instructionsKeyCallback!;
699-
if (
700-
state.columnsByDataType[action.currentColumn] ===
701-
ColumnTypes.NUMERICAL
702-
) {
703-
queueMicrotask(() => callback('selectedFeatureNumerical', null));
704-
} else if (
705-
state.columnsByDataType[action.currentColumn] ===
706-
ColumnTypes.CATEGORICAL
707-
) {
708-
queueMicrotask(() => callback('selectedFeatureCategorical', null));
702+
if (state.instructionsKeyCallback) {
703+
const callback = state.instructionsKeyCallback;
704+
if (
705+
state.columnsByDataType[action.currentColumn] ===
706+
ColumnTypes.NUMERICAL
707+
) {
708+
queueMicrotask(() => callback('selectedFeatureNumerical', null));
709+
} else if (
710+
state.columnsByDataType[action.currentColumn] ===
711+
ColumnTypes.CATEGORICAL
712+
) {
713+
queueMicrotask(() => callback('selectedFeatureCategorical', null));
714+
}
709715
}
710716
}
711717

@@ -750,10 +756,12 @@ export default function rootReducer(
750756
}
751757
if (action.type === SET_SHOW_RESULTS_DETAILS) {
752758
// Deferred — see SET_IMPORTED_DATA comment.
753-
const callback = state.instructionsKeyCallback!;
754-
queueMicrotask(() =>
755-
callback(action.show ? 'resultsDetails' : 'results', null),
756-
);
759+
if (state.instructionsKeyCallback) {
760+
const callback = state.instructionsKeyCallback;
761+
queueMicrotask(() =>
762+
callback(action.show ? 'resultsDetails' : 'results', null),
763+
);
764+
}
757765
return {
758766
...state,
759767
showResultsDetails: action.show,

0 commit comments

Comments
 (0)