MyCrypto/common/reducers/notifications.js

33 lines
865 B
JavaScript
Raw Normal View History

2017-06-21 23:31:59 +00:00
// @flow
2017-06-22 21:16:21 +00:00
import type {
NotificationsAction,
Notification,
ShowNotificationAction,
CloseNotificationAction
} from 'actions/notifications';
2017-06-21 23:31:59 +00:00
type State = Notification[];
const initialState: State = [];
2017-06-22 21:16:21 +00:00
function showNotification(state: State, action: ShowNotificationAction): State {
return state.concat(action.payload);
}
function closeNotification(state, action: CloseNotificationAction): State {
state = [...state];
state.splice(state.indexOf(action.payload), 1);
return state;
}
2017-06-21 23:31:59 +00:00
export function notifications(state: State = initialState, action: NotificationsAction): State {
switch (action.type) {
case 'SHOW_NOTIFICATION':
2017-06-22 21:16:21 +00:00
return showNotification(state, action);
2017-06-21 23:31:59 +00:00
case 'CLOSE_NOTIFICATION':
2017-06-22 21:16:21 +00:00
return closeNotification(state, action);
2017-06-21 23:31:59 +00:00
default:
return state;
}
}