Skip to content

Commit

Permalink
Memoise a couple of selectors (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
azangru authored May 22, 2024
1 parent 18aa31f commit ec36402
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import { createSelector } from '@reduxjs/toolkit';

import {
getEntityViewerActiveGenomeId,
getEntityViewerActiveEntityId
Expand All @@ -26,18 +28,19 @@ import {
SortingRule
} from './geneViewTranscriptsSlice';

const getSliceForGene = (
state: RootState
): TranscriptsStatePerGene | undefined => {
const activeGenomeId = getEntityViewerActiveGenomeId(state);
const activeEntityId = getEntityViewerActiveEntityId(state);
if (!activeGenomeId || !activeEntityId) {
return;
const getSliceForGene = createSelector(
[
getEntityViewerActiveGenomeId,
getEntityViewerActiveEntityId,
(state: RootState) => state
],
(genomeId, entityId, state): TranscriptsStatePerGene | undefined => {
if (!genomeId || !entityId) {
return;
}
return state.entityViewer.geneView.transcripts[genomeId]?.[entityId];
}
return state.entityViewer.geneView.transcripts[activeGenomeId]?.[
activeEntityId
];
};
);

export const getExpandedTranscriptIds = (state: RootState): string[] => {
const transcriptsSlice = getSliceForGene(state);
Expand All @@ -58,10 +61,12 @@ export const getExpandedTranscriptMoreInfoIds = (
return transcriptsSlice?.expandedMoreInfoIds ?? [];
};

export const getFilters = (state: RootState): Filters => {
const transcriptsSlice = getSliceForGene(state);
return transcriptsSlice?.filters ?? {};
};
export const getFilters = createSelector(
[getSliceForGene],
(transcriptsSlice): Filters => {
return transcriptsSlice?.filters ?? {};
}
);

export const getSortingRule = (state: RootState): SortingRule => {
const transcriptsSlice = getSliceForGene(state);
Expand Down

0 comments on commit ec36402

Please sign in to comment.