MyCrypto/common/reducers/notifications.js

36 lines
828 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
const initialState: State = [];
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 = initialState,
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
}