@bigfishtv/cockpit
Version:
38 lines (29 loc) • 2 kB
JavaScript
;
exports.__esModule = true;
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
*/
exports.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;
};
var _ActionTypes = require('../constants/ActionTypes');
var ActionTypes = _interopRequireWildcard(_ActionTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
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
*/