MyCrypto/common/reducers/notifications.js

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