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.

reducer.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. HIDE_NOTIFICATION,
  4. SET_NOTIFICATIONS_ENABLED,
  5. SHOW_NOTIFICATION
  6. } from './actionTypes';
  7. /**
  8. * The initial state of the feature notifications.
  9. *
  10. * @type {array}
  11. */
  12. const DEFAULT_STATE = {
  13. enabled: true,
  14. notifications: []
  15. };
  16. /**
  17. * Reduces redux actions which affect the display of notifications.
  18. *
  19. * @param {Object} state - The current redux state.
  20. * @param {Object} action - The redux action to reduce.
  21. * @returns {Object} The next redux state which is the result of reducing the
  22. * specified {@code action}.
  23. */
  24. ReducerRegistry.register('features/notifications',
  25. (state = DEFAULT_STATE, action) => {
  26. switch (action.type) {
  27. case HIDE_NOTIFICATION:
  28. return {
  29. ...state,
  30. notifications: state.notifications.filter(
  31. notification => notification.uid !== action.uid)
  32. };
  33. case SET_NOTIFICATIONS_ENABLED:
  34. return {
  35. ...state,
  36. enabled: action.enabled
  37. };
  38. case SHOW_NOTIFICATION:
  39. return {
  40. ...state,
  41. notifications: [
  42. ...state.notifications,
  43. {
  44. component: action.component,
  45. props: action.props,
  46. timeout: action.timeout,
  47. uid: action.uid
  48. }
  49. ]
  50. };
  51. }
  52. return state;
  53. });