Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mayask/react-redux-modal-provider. Redux-powered abstract React modal state manager
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import { ActionType } from './action';
const reducer = ( state = { stack: [], }, action,) => { switch (action.type) { case ActionType.SHOW: return { ...state, stack: [ ...state.stack, { id: new Date().valueOf(), component: action.component, props: action.props, show: true, delayBeforeRemoveMsec: action.delayBeforeRemoveMsec, }, ], };
case ActionType.HIDE: const targetModal = state.stack.find(modal => modal.id === action.id)
if (!targetModal) { return state; }
return { ...state, stack: [ ...state.stack.filter(modal => state.stack.indexOf(modal) < state.stack.indexOf(targetModal)), { ...targetModal, show: false, }, ...state.stack.filter(modal => state.stack.indexOf(modal) > state.stack.indexOf(targetModal)), ], };
case ActionType.REMOVE: return { ...state, stack: state.stack.filter(modal => modal.id !== action.id), };
default: return state; }};
export default reducer;