alerts.js 594 B

123456789101112131415161718192021222324252627282930
  1. import { List as ImmutableList } from 'immutable';
  2. import {
  3. ALERT_SHOW,
  4. ALERT_DISMISS,
  5. ALERT_CLEAR,
  6. } from '../actions/alerts';
  7. const initialState = ImmutableList([]);
  8. let id = 0;
  9. const addAlert = (state, alert) =>
  10. state.push({
  11. key: id++,
  12. ...alert,
  13. });
  14. export default function alerts(state = initialState, action) {
  15. switch(action.type) {
  16. case ALERT_SHOW:
  17. return addAlert(state, action.alert);
  18. case ALERT_DISMISS:
  19. return state.filterNot(item => item.key === action.alert.key);
  20. case ALERT_CLEAR:
  21. return state.clear();
  22. default:
  23. return state;
  24. }
  25. }