summaryrefslogtreecommitdiff
path: root/src/reducers/simulation-mode.js
blob: 020414686e4bd4ebbbe14e629a15a4b226c896dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { OPEN_EXPERIMENT_SUCCEEDED } from "../actions/experiments";
import { CHANGE_LOAD_METRIC } from "../actions/simulation/load-metric";
import { SET_PLAYING } from "../actions/simulation/playback";
import {
  GO_TO_TICK,
  SET_LAST_SIMULATED_TICK
} from "../actions/simulation/tick";
import { OPEN_SIMULATION_SUCCEEDED } from "../actions/simulations";

export function currentExperimentId(state = -1, action) {
  switch (action.type) {
    case OPEN_EXPERIMENT_SUCCEEDED:
      return action.experimentId;
    case OPEN_SIMULATION_SUCCEEDED:
      return -1;
    default:
      return state;
  }
}

export function currentTick(state = 0, action) {
  switch (action.type) {
    case GO_TO_TICK:
      return action.tick;
    case OPEN_EXPERIMENT_SUCCEEDED:
      return 0;
    default:
      return state;
  }
}

export function loadMetric(state = "LOAD", action) {
  switch (action.type) {
    case CHANGE_LOAD_METRIC:
      return action.metric;
    default:
      return state;
  }
}

export function isPlaying(state = false, action) {
  switch (action.type) {
    case SET_PLAYING:
      return action.playing;
    case OPEN_EXPERIMENT_SUCCEEDED:
      return false;
    default:
      return state;
  }
}

export function lastSimulatedTick(state = -1, action) {
  switch (action.type) {
    case SET_LAST_SIMULATED_TICK:
      return action.tick;
    case OPEN_EXPERIMENT_SUCCEEDED:
      return -1;
    default:
      return state;
  }
}