You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
633 B

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