From a43da7e13e35d49139ba709ad16ec24b7993d0b2 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Wed, 21 Feb 2024 17:39:53 -0500 Subject: [PATCH] Export AppDispatch to clean up Redux types --- src/lib/weechat/action_transformer.ts | 17 ++++------------- src/lib/weechat/connection.ts | 8 +++----- src/store/index.ts | 2 ++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/lib/weechat/action_transformer.ts b/src/lib/weechat/action_transformer.ts index 1404859..1e160bf 100644 --- a/src/lib/weechat/action_transformer.ts +++ b/src/lib/weechat/action_transformer.ts @@ -1,4 +1,4 @@ -import { StoreState } from '../../store'; +import { AppDispatch, StoreState } from '../../store'; type KeyFn = (t: T) => string; type MapFn = (a: A) => A | B; @@ -53,10 +53,7 @@ export const transformToReduxAction = (data: WeechatResponse) => { const object = data.objects[0] as WeechatObject<{ full_name: string }[]>; const fullName = object.content[0].full_name; - return ( - dispatch: (action: object) => void, - getState: () => StoreState - ) => { + return (dispatch: AppDispatch, getState: () => StoreState) => { const state: StoreState = getState(); const buffer = Object.values(state.buffers).find( (buffer: WeechatBuffer) => buffer.full_name == fullName @@ -76,10 +73,7 @@ export const transformToReduxAction = (data: WeechatResponse) => { >; const line = object.content[0]; - return ( - dispatch: (action: object) => void, - getState: () => StoreState - ) => { + return (dispatch: AppDispatch, getState: () => StoreState) => { const state: StoreState = getState(); const { date, date_printed, ...restLine } = line; @@ -152,10 +146,7 @@ export const transformToReduxAction = (data: WeechatResponse) => { case 'hotlist': { const object = data.objects[0] as WeechatObject; - return ( - dispatch: (action: object) => void, - getState: () => StoreState - ) => { + return (dispatch: AppDispatch, getState: () => StoreState) => { const state: StoreState = getState(); dispatch({ diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts index ac866cf..9535bec 100644 --- a/src/lib/weechat/connection.ts +++ b/src/lib/weechat/connection.ts @@ -1,13 +1,11 @@ import { WeeChatProtocol } from './parser'; import { transformToReduxAction } from './action_transformer'; -import { StoreState } from '../../store'; -import { ThunkDispatch } from 'redux-thunk'; -import { AnyAction } from 'redux'; +import { AppDispatch } from '../../store'; const protocol = new WeeChatProtocol(); export default class WeechatConnection { - dispatch: ThunkDispatch; + dispatch: AppDispatch; hostname: string; password: string; ssl: boolean = true; @@ -19,7 +17,7 @@ export default class WeechatConnection { reconnect: boolean; constructor( - dispatch: ThunkDispatch, + dispatch: AppDispatch, host: string, password: string, ssl: boolean, diff --git a/src/store/index.ts b/src/store/index.ts index f910436..39ef5f5 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -32,6 +32,8 @@ export type StoreState = { nicklists: NicklistState; }; +export type AppDispatch = typeof store.dispatch; + const initialState: AppState = { connected: false, currentBufferId: null