UNPKG

@e-group/redux-modules

Version:

eGroup team react-redux modules that share across projects.

60 lines (52 loc) 1.48 kB
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import { handleActions } from 'redux-actions'; import { fromJS, Map, isImmutable, merge } from '@e-group/immutable'; import { INITIALIZE_SNACKBAR, OPEN_SNACKBAR, CLOSE_SNACKBAR, SET_SNACKBAR_DATA } from '../../snackbars'; const initialState = fromJS({}); /** * Reducer */ export const snackbars = handleActions({ [INITIALIZE_SNACKBAR]: (state, action) => { if (action.payload) { const name = String(action.payload); return state.update(name, snackbarState => { if (isImmutable(snackbarState)) { return snackbarState; } return Map({ isOpen: false }); }); } return state; }, [OPEN_SNACKBAR]: (state, action) => { if (action.payload) { return state.setIn([action.payload, 'isOpen'], true); } return state; }, [CLOSE_SNACKBAR]: (state, action) => { if (action.payload) { return state.setIn([action.payload, 'isOpen'], false); } return state; }, [SET_SNACKBAR_DATA]: (state, action) => { if (action.payload) { const _ref = action.payload, name = _ref.name, other = _objectWithoutProperties(_ref, ["name"]); if (name) { return state.update(name, el => { if (el) { return merge(el, other); } return el; }); } } return state; } }, initialState);