reducer.ts
1 import * as types from './types'; 2 3 export const INITIAL_STATE: types.NotificationState = []; 4 5 function showNotification( 6 state: types.NotificationState, 7 action: types.ShowNotificationAction 8 ): types.NotificationState { 9 return state.concat(action.payload); 10 } 11 12 function closeNotification( 13 state: types.NotificationState, 14 action: types.CloseNotificationAction 15 ): types.NotificationState { 16 state = [...state]; 17 state.splice(state.indexOf(action.payload), 1); 18 return state; 19 } 20 21 export function notificationsReducer( 22 state: types.NotificationState = INITIAL_STATE, 23 action: types.NotificationsAction 24 ): types.NotificationState { 25 switch (action.type) { 26 case types.NotificationsActions.SHOW: 27 return showNotification(state, action); 28 case types.NotificationsActions.CLOSE: 29 return closeNotification(state, action); 30 default: 31 return state; 32 } 33 }