env.js 733 字节
Newer Older
J
Jason Park 已提交
1 2 3 4 5
import { combineActions, createAction, handleActions } from 'redux-actions';

const prefix = 'ENV';

const setCategories = createAction(`${prefix}/SET_CATEGORIES`, categories => ({ categories }));
J
Jason Park 已提交
6
const setDirectory = createAction(`${prefix}/SELECT_FILE`, (categoryKey, algorithmKey, fileKey) => ({
J
Jason Park 已提交
7 8 9 10 11 12 13
  categoryKey,
  algorithmKey,
  fileKey,
}));

export const actions = {
  setCategories,
J
Jason Park 已提交
14
  setDirectory,
J
Jason Park 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28
};

const immutables = {};

const mutables = {
  categories: null,
  categoryKey: null,
  algorithmKey: null,
  fileKey: null,
};

export default handleActions({
  [combineActions(
    setCategories,
J
Jason Park 已提交
29
    setDirectory,
J
Jason Park 已提交
30 31 32 33 34 35 36 37
  )]: (state, { payload }) => ({
    ...state,
    ...payload,
  }),
}, {
  ...immutables,
  ...mutables,
});