MyCrypto/common/reducers/notifications.js

33 lines
865 B
JavaScript
Raw Normal View History

2017-06-21 16:31:59 -07:00
// @flow
2017-06-22 14:16:21 -07:00
import type {
NotificationsAction,
Notification,
ShowNotificationAction,
CloseNotificationAction
} from 'actions/notifications';
2017-06-21 16:31:59 -07:00
type State = Notification[];
const initialState: State = [];
2017-06-22 14:16:21 -07: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 16:31:59 -07:00
export function notifications(state: State = initialState, action: NotificationsAction): State {
switch (action.type) {
case 'SHOW_NOTIFICATION':
2017-06-22 14:16:21 -07:00
return showNotification(state, action);
2017-06-21 16:31:59 -07:00
case 'CLOSE_NOTIFICATION':
2017-06-22 14:16:21 -07:00
return closeNotification(state, action);
2017-06-21 16:31:59 -07:00
default:
return state;
}
}