@bigfishtv/cockpit
Version:
27 lines (23 loc) • 711 B
JavaScript
/**
* @module Reducers/notifications
*/
import * as ActionTypes from '../constants/ActionTypes'
const 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(state = initialState, action) {
switch (action.type) {
case ActionTypes.NOTIFICATION_ADDED:
return [...state, { ...action.notification }]
case ActionTypes.NOTIFICATION_DISMISSED:
return state.map(notification =>
notification.id === action.id ? { ...notification, dismissed: true } : notification
)
}
return state
}