Skip to content

Commit

Permalink
Export AppDispatch to clean up Redux types
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Feb 21, 2024
1 parent 41b2b4e commit a43da7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
17 changes: 4 additions & 13 deletions src/lib/weechat/action_transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StoreState } from '../../store';
import { AppDispatch, StoreState } from '../../store';

type KeyFn<T> = (t: T) => string;
type MapFn<A, B> = (a: A) => A | B;
Expand Down Expand Up @@ -53,10 +53,7 @@ export const transformToReduxAction = (data: WeechatResponse<unknown>) => {
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
Expand All @@ -76,10 +73,7 @@ export const transformToReduxAction = (data: WeechatResponse<unknown>) => {
>;
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;

Expand Down Expand Up @@ -152,10 +146,7 @@ export const transformToReduxAction = (data: WeechatResponse<unknown>) => {
case 'hotlist': {
const object = data.objects[0] as WeechatObject<WeechatHotlist[]>;

return (
dispatch: (action: object) => void,
getState: () => StoreState
) => {
return (dispatch: AppDispatch, getState: () => StoreState) => {
const state: StoreState = getState();

dispatch({
Expand Down
8 changes: 3 additions & 5 deletions src/lib/weechat/connection.ts
Original file line number Diff line number Diff line change
@@ -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<StoreState, undefined, AnyAction>;
dispatch: AppDispatch;
hostname: string;
password: string;
ssl: boolean = true;
Expand All @@ -19,7 +17,7 @@ export default class WeechatConnection {
reconnect: boolean;

constructor(
dispatch: ThunkDispatch<StoreState, undefined, AnyAction>,
dispatch: AppDispatch,
host: string,
password: string,
ssl: boolean,
Expand Down
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type StoreState = {
nicklists: NicklistState;
};

export type AppDispatch = typeof store.dispatch;

const initialState: AppState = {
connected: false,
currentBufferId: null
Expand Down

0 comments on commit a43da7e

Please sign in to comment.