reducers.ts 642 B

1234567891011121314151617181920212223
  1. import { AppNotification, AlertsState } from 'app/types';
  2. import { Action, ActionTypes } from './actions';
  3. export const initialState: AlertsState = {
  4. alerts: [] as AppNotification[],
  5. };
  6. export const alertsReducer = (state = initialState, action: Action): AlertsState => {
  7. switch (action.type) {
  8. case ActionTypes.AddAppNotification:
  9. return { ...state, alerts: state.alerts.concat([action.payload]) };
  10. case ActionTypes.ClearAppNotification:
  11. return {
  12. ...state,
  13. alerts: state.alerts.filter(alert => alert !== action.payload),
  14. };
  15. }
  16. return state;
  17. };
  18. export default {
  19. alerts: alertsReducer,
  20. };