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

@ -8,9 +8,8 @@ import { store } from '..'
import { ApiUrlActionType, ApiUrlObject, SetApiUrlAction } from './types'
export const setApiUrl = (state: ApiUrlObject): void => {
const action: SetApiUrlAction = {
store.dispatch({
type: ApiUrlActionType.SET_API_URL,
state
}
store.dispatch(action)
} as SetApiUrlAction)
}

View file

@ -5,7 +5,7 @@
*/
import { Reducer } from 'redux'
import { ApiUrlActions, ApiUrlActionType, ApiUrlObject, SetApiUrlAction } from './types'
import { ApiUrlActions, ApiUrlActionType, ApiUrlObject } from './types'
export const initialState: ApiUrlObject = {
apiUrl: ''
@ -17,7 +17,7 @@ export const ApiUrlReducer: Reducer<ApiUrlObject, ApiUrlActions> = (
) => {
switch (action.type) {
case ApiUrlActionType.SET_API_URL:
return (action as SetApiUrlAction).state
return action.state
default:
return state
}

View file

@ -10,11 +10,10 @@ export enum ApiUrlActionType {
SET_API_URL = 'api-url/set'
}
export interface ApiUrlActions extends Action<ApiUrlActionType> {
type: ApiUrlActionType
}
export type ApiUrlActions = SetApiUrlAction
export interface SetApiUrlAction extends ApiUrlActions {
export interface SetApiUrlAction extends Action<ApiUrlActionType> {
type: ApiUrlActionType.SET_API_URL
state: ApiUrlObject
}