MyCrypto/common/reducers/notifications.js

36 lines
837 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 {
2017-07-02 05:49:06 +00:00
NotificationsAction,
Notification,
ShowNotificationAction,
CloseNotificationAction
2017-06-22 21:16:21 +00:00
} from 'actions/notifications';
2017-06-21 23:31:59 +00:00
2017-06-26 22:27:55 +00:00
export type State = Notification[];
2017-06-21 23:31:59 +00:00
export const INITIAL_STATE: State = [];
2017-06-21 23:31:59 +00:00
2017-06-22 21:16:21 +00:00
function showNotification(state: State, action: ShowNotificationAction): State {
2017-07-02 05:49:06 +00:00
return state.concat(action.payload);
2017-06-22 21:16:21 +00:00
}
function closeNotification(state, action: CloseNotificationAction): State {
2017-07-02 05:49:06 +00:00
state = [...state];
state.splice(state.indexOf(action.payload), 1);
return state;
2017-06-22 21:16:21 +00:00
}
2017-07-02 05:49:06 +00:00
export function notifications(
state: State = INITIAL_STATE,
2017-07-02 05:49:06 +00:00
action: NotificationsAction
): State {
switch (action.type) {
case 'SHOW_NOTIFICATION':
return showNotification(state, action);
case 'CLOSE_NOTIFICATION':
return closeNotification(state, action);
default:
return state;
}
2017-06-21 23:31:59 +00:00
}