Skip to content

Commit

Permalink
Merge pull request #1263 from Arnei/memoize-selectVideos
Browse files Browse the repository at this point in the history
Add memoization to "selectVideos" selector
  • Loading branch information
geichelberger authored Mar 20, 2024
2 parents 56ed7ed + 5ddadad commit 5d1e82c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/redux/videoSlice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSlice, nanoid, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
import { createSlice, nanoid, createAsyncThunk, PayloadAction, createSelector } from "@reduxjs/toolkit";
import { client } from "../util/client";

import { Segment, httpRequestState, Track, Workflow, SubtitlesFromOpencast } from "../types";
Expand Down Expand Up @@ -286,7 +286,6 @@ const videoSlice = createSlice({
selectWaveformImages: state => state.waveformImages,
selectOriginalThumbnails: state => state.originalThumbnails,
// Selectors mainly pertaining to the information fetched from Opencast
selectVideos: state => state.tracks.filter((track: Track) => track.video_stream.available === true),
selectVideoURL: state => state.videoURLs,
selectVideoCount: state => state.videoCount,
selectDuration: state => state.duration,
Expand Down Expand Up @@ -427,6 +426,11 @@ export const { setTrackEnabled, setIsPlaying, setIsPlayPreview, setIsMuted, setV
removeThumbnail, setLock, cut, markAsDeletedOrAlive, setSelectedWorkflowIndex, mergeLeft, mergeRight, mergeAll,
setPreviewTriggered, setClickTriggered } = videoSlice.actions;

export const selectVideos = createSelector(
[(state: { videoState: { tracks: video["tracks"]; }; }) => state.videoState.tracks],
tracks => tracks.filter((track: Track) => track.video_stream.available === true)
);

// Export selectors
export const {
selectIsPlaying,
Expand All @@ -444,7 +448,6 @@ export const {
selectHasChanges,
selectWaveformImages,
selectOriginalThumbnails,
selectVideos,
selectVideoURL,
selectVideoCount,
selectDuration,
Expand Down

0 comments on commit 5d1e82c

Please sign in to comment.