UNPKG

@bigfishtv/cockpit

Version:

31 lines (26 loc) 1.11 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** * @module Reducers/notifications */ import * as ActionTypes from '../constants/ActionTypes'; var initialState = []; /** * Reducer for managing notifications/flash messages * @param {Object} state * @param {Object} action * @param {String} action.type - const action type from constants/ActionTypes * @return {Object} returns state */ export default function () { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments[1]; switch (action.type) { case ActionTypes.NOTIFICATION_ADDED: return [].concat(state, [_extends({}, action.notification)]); case ActionTypes.NOTIFICATION_DISMISSED: return state.map(function (notification) { return notification.id === action.id ? _extends({}, notification, { dismissed: true }) : notification; }); } return state; }