aboutsummaryrefslogtreecommitdiff
path: root/src/reducers/input.js
blob: dca26e2a42172f225ee1f4423f18b761d79f3192 (plain) (blame)
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
import actions from '../actions';

const defaultState = {
  keys: [],
  keymaps: {}
};

export default function reducer(state = defaultState, action = {}) {
  switch (action.type) {
  case actions.INPUT_KEY_PRESS:
    return Object.assign({}, state, {
      keys: state.keys.concat([
        {
          code: action.code,
          ctrl: action.ctrl
        }
      ])
    });
  case actions.INPUT_CLEAR_KEYS:
    return Object.assign({}, state, {
      keys: [],
    });
  case actions.INPUT_SET_KEYMAPS:
    return Object.assign({}, state, {
      keymaps: action.keymaps,
      keys: [],
    });
  default:
    return state;
  }
}