Skip to content

Commit 2f4d1e3

Browse files
fix(client): improve editor performance (freeCodeCamp#55726)
1 parent da5e460 commit 2f4d1e3

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

client/src/templates/Challenges/redux/selectors.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export const challengeFilesSelector = state => state[ns].challengeFiles;
1616
export const challengeMetaSelector = state => state[ns].challengeMeta;
1717
export const challengeTestsSelector = state => state[ns].challengeTests;
1818
export const consoleOutputSelector = state => state[ns].consoleOut;
19-
export const completedChallengesIdsSelector = state =>
20-
completedChallengesSelector(state).map(node => node.id);
19+
export const completedChallengesIdsSelector = createSelector(
20+
completedChallengesSelector,
21+
completedChallenges => completedChallenges.map(node => node.id)
22+
);
2123
export const isChallengeCompletedSelector = state => {
2224
const completedChallenges = completedChallengesSelector(state);
2325
const { id: currentChallengeId } = challengeMetaSelector(state);
@@ -119,17 +121,13 @@ export const currentBlockIdsSelector = createSelector(
119121
}
120122
);
121123

122-
export const completedChallengesInBlockSelector = state => {
123-
const completedChallengesIds = completedChallengesIdsSelector(state);
124-
const currentBlockIds = currentBlockIdsSelector(state);
125-
const { id } = challengeMetaSelector(state);
126-
127-
return getCompletedChallengesInBlock(
128-
completedChallengesIds,
129-
currentBlockIds,
130-
id
131-
);
132-
};
124+
export const completedChallengesInBlockSelector = createSelector(
125+
completedChallengesIdsSelector,
126+
currentBlockIdsSelector,
127+
challengeMetaSelector,
128+
(completedChallengesIds, currentBlockIds, { id }) =>
129+
getCompletedChallengesInBlock(completedChallengesIds, currentBlockIds, id)
130+
);
133131

134132
export const completedPercentageSelector = createSelector(
135133
isSignedInSelector,

0 commit comments

Comments
 (0)