mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor: memoize only selectors that compute (#58499)
This commit is contained in:
committed by
GitHub
parent
1738b1f05f
commit
0b9d914602
@@ -6,7 +6,6 @@ import { connect } from 'react-redux';
|
|||||||
import { HandlerProps } from 'react-reflex';
|
import { HandlerProps } from 'react-reflex';
|
||||||
import { useMediaQuery } from 'react-responsive';
|
import { useMediaQuery } from 'react-responsive';
|
||||||
import { bindActionCreators, Dispatch } from 'redux';
|
import { bindActionCreators, Dispatch } from 'redux';
|
||||||
import { createStructuredSelector } from 'reselect';
|
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { editor } from 'monaco-editor';
|
import { editor } from 'monaco-editor';
|
||||||
import type { FitAddon } from 'xterm-addon-fit';
|
import type { FitAddon } from 'xterm-addon-fit';
|
||||||
@@ -22,6 +21,7 @@ import {
|
|||||||
ChallengeNode,
|
ChallengeNode,
|
||||||
CompletedChallenge,
|
CompletedChallenge,
|
||||||
ResizeProps,
|
ResizeProps,
|
||||||
|
SavedChallenge,
|
||||||
SavedChallengeFiles,
|
SavedChallengeFiles,
|
||||||
Test
|
Test
|
||||||
} from '../../../redux/prop-types';
|
} from '../../../redux/prop-types';
|
||||||
@@ -72,11 +72,11 @@ import { mergeChallengeFiles } from './saved-challenges';
|
|||||||
import './classic.css';
|
import './classic.css';
|
||||||
import '../components/test-frame.css';
|
import '../components/test-frame.css';
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = (state: unknown) => ({
|
||||||
challengeFiles: challengeFilesSelector,
|
challengeFiles: challengeFilesSelector(state) as ChallengeFiles,
|
||||||
output: consoleOutputSelector,
|
output: consoleOutputSelector(state) as string[],
|
||||||
isChallengeCompleted: isChallengeCompletedSelector,
|
isChallengeCompleted: isChallengeCompletedSelector(state) as boolean,
|
||||||
savedChallenges: savedChallengesSelector
|
savedChallenges: savedChallengesSelector(state) as SavedChallenge[]
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch: Dispatch) =>
|
const mapDispatchToProps = (dispatch: Dispatch) =>
|
||||||
@@ -120,7 +120,7 @@ interface ShowClassicProps extends Pick<PreviewProps, 'previewMounted'> {
|
|||||||
openModal: (modal: string) => void;
|
openModal: (modal: string) => void;
|
||||||
setEditorFocusability: (canFocus: boolean) => void;
|
setEditorFocusability: (canFocus: boolean) => void;
|
||||||
setIsAdvancing: (arg: boolean) => void;
|
setIsAdvancing: (arg: boolean) => void;
|
||||||
savedChallenges: CompletedChallenge[];
|
savedChallenges: SavedChallenge[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReflexLayout {
|
interface ReflexLayout {
|
||||||
|
|||||||
@@ -20,11 +20,10 @@ export const completedChallengesIdsSelector = createSelector(
|
|||||||
completedChallengesSelector,
|
completedChallengesSelector,
|
||||||
completedChallenges => completedChallenges.map(node => node.id)
|
completedChallenges => completedChallenges.map(node => node.id)
|
||||||
);
|
);
|
||||||
export const isChallengeCompletedSelector = state => {
|
export const isChallengeCompletedSelector = createSelector(
|
||||||
const completedChallenges = completedChallengesSelector(state);
|
[completedChallengesIdsSelector, challengeMetaSelector],
|
||||||
const { id: currentChallengeId } = challengeMetaSelector(state);
|
(ids, meta) => ids.includes(meta.id)
|
||||||
return completedChallenges.some(({ id }) => id === currentChallengeId);
|
);
|
||||||
};
|
|
||||||
export const isCodeLockedSelector = state => state[ns].isCodeLocked;
|
export const isCodeLockedSelector = state => state[ns].isCodeLocked;
|
||||||
export const isCompletionModalOpenSelector = state =>
|
export const isCompletionModalOpenSelector = state =>
|
||||||
state[ns].modal.completion;
|
state[ns].modal.completion;
|
||||||
|
|||||||
Reference in New Issue
Block a user