summaryrefslogtreecommitdiff
path: root/app/client/live/reducer.js
blob: e14a0397d6b4b1b6934f6ce841362297e509c46d (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
import { combineReducers } from 'redux'

const liveInitialState = {
  loading: false,
  error: null,
  opt: {},
  checkpoints: [],
  checkpoint_dir: ['latest'],
  sequences: [],
}

const liveReducer = (state = liveInitialState, action) => {
  let results;

  switch(action.type) {
    case 'LOAD_PARAMS':
      if (! action.opt || ! Object.keys(action.opt).length) {
        return state
      }
      return {
        ...state,
        loading: false,
        error: null,
        opt: action.opt,
      }

    case 'SET_PARAM':
      return {
        ...state,
        opt: {
          ...state.opt,
          [action.key]: action.value,
        }
      }

    case 'LIST_CHECKPOINTS':
      return {
        ...state,
        checkpoints: action.checkpoints,
      }

    case 'LIST_CHECKPOINT_DIR':
      return {
        ...state,
        checkpoint_dir: action.checkpoint_dir,
      }

    case 'LIST_SEQUENCES':
      return {
        ...state,
        sequences: action.sequences,
      }

    default:
      return state
  }
}

export default liveReducer