Skip to content

Commit

Permalink
Data layer also checks to see if it's legal before allowing updating.…
Browse files Browse the repository at this point in the history
… Part of #10.
  • Loading branch information
jkomoros committed Nov 21, 2021
1 parent 72c7c55 commit 2827e51
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/actions/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import {
selectFrameIndex,
selectRunIndex,
selectCurrentSimulationMaxRunIndex
selectCurrentSimulationMaxRunIndex,
selectCurrentSimulationRun
} from '../selectors.js';

export const loadData = (data) => {
Expand Down Expand Up @@ -41,8 +42,14 @@ export const updateSimulationIndex = (index) => (dispatch) => {
dispatch(canonicalizePath());
};

export const updateFrameIndex = (index) => (dispatch) => {
export const updateFrameIndex = (index) => (dispatch, getState) => {
if (typeof index == 'string') index = parseInt(index);
const state = getState();
const run = selectCurrentSimulationRun(state);
const maxFrameIndex = run ? run.maxFrameIndex : Number.MAX_SAFE_INTEGER;
if (index > maxFrameIndex) index = maxFrameIndex;
//no op
if (index == selectFrameIndex(state)) return;
dispatch({
type: UPDATE_FRAME_INDEX,
index,
Expand Down

0 comments on commit 2827e51

Please sign in to comment.