mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
Reorganize redux types to avoid unnecessary type casting
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
a221ce4255
commit
6a43d0c5fb
27 changed files with 113 additions and 153 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue