Reorganize redux types to avoid unnecessary type casting

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2021-07-21 22:52:49 +02:00
parent a221ce4255
commit 6a43d0c5fb
27 changed files with 113 additions and 153 deletions

View file

@ -5,23 +5,17 @@
*/
import { Reducer } from 'redux'
import {
DismissUiNotificationAction,
DispatchUiNotificationAction,
UiNotificationAction,
UiNotificationActionType,
UiNotificationState
} from './types'
import { UiNotificationActions, UiNotificationActionType, UiNotificationState } from './types'
export const UiNotificationReducer: Reducer<UiNotificationState, UiNotificationAction> = (
export const UiNotificationReducer: Reducer<UiNotificationState, UiNotificationActions> = (
state: UiNotificationState = [],
action: UiNotificationAction
action: UiNotificationActions
) => {
switch (action.type) {
case UiNotificationActionType.DISPATCH_NOTIFICATION:
return state.concat((action as DispatchUiNotificationAction).notification)
return state.concat(action.notification)
case UiNotificationActionType.DISMISS_NOTIFICATION:
return dismissNotification(state, (action as DismissUiNotificationAction).notificationId)
return dismissNotification(state, action.notificationId)
default:
return state
}

View file

@ -28,16 +28,14 @@ export interface UiNotification {
buttons?: UiNotificationButton[]
}
export interface UiNotificationAction extends Action<UiNotificationActionType> {
type: UiNotificationActionType
}
export type UiNotificationActions = DispatchUiNotificationAction | DismissUiNotificationAction
export interface DispatchUiNotificationAction extends UiNotificationAction {
export interface DispatchUiNotificationAction extends Action<UiNotificationActionType> {
type: UiNotificationActionType.DISPATCH_NOTIFICATION
notification: UiNotification
}
export interface DismissUiNotificationAction extends UiNotificationAction {
export interface DismissUiNotificationAction extends Action<UiNotificationActionType> {
type: UiNotificationActionType.DISMISS_NOTIFICATION
notificationId: number
}