import { createReducer } from 'utils/functions' ; import { TypeKeys } from './constants' ; import { Notification , AddNotificationAction , RemoveNotificationAction } from './actions' ; export type NotificationState = Notification [ ] ; export const INITIAL_STATE = [ ] ; function addNotification ( state , action ) { return [ ... state , action . payload ] ; } function removeNotification ( state , action ) { return [ ... state . filter ( ( _ , i ) => i !== action . payload ) ] ; } export const notificationReducer = createReducer ( INITIAL_STATE , { [ TypeKeys . ADD_NOTIFICATION ] : addNotification , [ TypeKeys . REMOVE_NOTIFICATION ] : removeNotification } ) ;