@e-group/redux-modules
Version:
eGroup team react-redux modules that share across projects.
60 lines (52 loc) • 1.46 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import { handleActions } from 'redux-actions';
import { fromJS, Map, isImmutable, merge } from '@e-group/immutable';
import { INITIALIZE_DIALOG, OPEN_DIALOG, CLOSE_DIALOG, SET_DIALOG_DATA } from '../../dialogs';
const initialState = fromJS({});
/**
* Reducer
*/
export const dialogs = handleActions({
[INITIALIZE_DIALOG]: (state, action) => {
if (action.payload) {
const name = String(action.payload);
return state.update(name, dialogState => {
if (isImmutable(dialogState)) {
return dialogState;
}
return Map({
isOpen: false
});
});
}
return state;
},
[OPEN_DIALOG]: (state, action) => {
if (action.payload) {
return state.setIn([action.payload, 'isOpen'], true);
}
return state;
},
[CLOSE_DIALOG]: (state, action) => {
if (action.payload) {
return state.setIn([action.payload, 'isOpen'], false);
}
return state;
},
[SET_DIALOG_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);