Skip to content

Commit fddaabd

Browse files
author
Péter Hauszknecht
committed
type variables abridgment
1 parent e0ebe01 commit fddaabd

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/store/middlewares/thunk.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { Middleware, GetState, Dispatch, Reducer, Store } from '../types';
22

3-
export interface ThunkMiddleware<State, ExtraArgument>
4-
extends Middleware<State, Reducer<State>, Thunk<State, ExtraArgument>> {
5-
(store: Store<State, Reducer<State> | Delegate<State, ExtraArgument>>): {
6-
(next: Dispatch<Reducer<State>, State>): Dispatch<Delegate<State, ExtraArgument>>;
3+
export interface ThunkMiddleware<S, EA>
4+
extends Middleware<S, Reducer<S>, Thunk<S, EA>> {
5+
(store: Store<S, Reducer<S> | Delegate<S, EA>>): {
6+
(next: Dispatch<Reducer<S>, S>): Dispatch<Delegate<S, EA>>;
77
};
8-
withExtraArgument: <EA>(extraArgument: EA) => ThunkMiddleware<State, EA>;
8+
withExtraArgument: <EA>(extraArgument: EA) => ThunkMiddleware<S, EA>;
99
}
1010

11-
export interface Delegate<State, ExtraArgument, Return = any> {
12-
(dispatch: ThunkDispatch<State, ExtraArgument>, getState: GetState<State>, extraArgument: ExtraArgument): Return;
11+
export interface Delegate<S, EA, RE = any> {
12+
(dispatch: ThunkDispatch<S, EA>, getState: GetState<S>, extraArgument: EA): RE;
1313
}
1414

15-
export interface Thunk<State, ExtraArgument, Return = any> {
16-
(state: State): Delegate<State, ExtraArgument, Return>;
15+
export interface Thunk<S, EA, RE = any> {
16+
(state: S): Delegate<S, EA, RE>;
1717
}
1818

19-
export interface ThunkDispatch<State, ExtraArgument> extends Dispatch<Reducer<State>, State> {
20-
<Return>(thunk: Thunk<State, ExtraArgument, Return>): Return;
19+
export interface ThunkDispatch<S, EA> extends Dispatch<Reducer<S>, S> {
20+
<Return>(thunk: Thunk<S, EA, Return>): Return;
2121
}
2222

23-
const thunkFactory = <State, ExtraArgument>(extraArgument?: ExtraArgument) => {
23+
const thunkFactory = <S, EA>(extraArgument?: EA) => {
2424
const thunk = (store => next => reducer => {
2525
if (typeof reducer !== 'function') throw new Error('Thunk requires reducers as functions');
2626
const state = store.getState();
@@ -30,7 +30,7 @@ const thunkFactory = <State, ExtraArgument>(extraArgument?: ExtraArgument) => {
3030
next(_ => result);
3131
return reducer;
3232
}
33-
}) as ThunkMiddleware<State, ExtraArgument>;
33+
}) as ThunkMiddleware<S, EA>;
3434
thunk.withExtraArgument = thunkFactory;
3535
return thunk;
3636
};

src/store/types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export interface GetState<State> {
2-
(): State;
1+
export interface GetState<S> {
2+
(): S;
33
}
44

55
export interface Reducer<State> {
66
(state: State): State;
77
}
88

9-
export interface Dispatch<Reducer, State = any> {
10-
(reducer: Reducer): State;
9+
export interface Dispatch<R, S = any> {
10+
(reducer: R): S;
1111
}
1212

1313
export interface Listener {
@@ -18,15 +18,15 @@ export interface Unsubscribe {
1818
(): void;
1919
}
2020

21-
export interface Middleware<State, R1, R2> {
22-
(store: Store<State, R1>): {
23-
(next: Dispatch<R1, State>): Dispatch<R2>;
21+
export interface Middleware<S, R1, R2> {
22+
(store: Store<S, R1>): {
23+
(next: Dispatch<R1, S>): Dispatch<R2>;
2424
};
2525
}
2626

27-
export interface Store<State, R = Reducer<State>> {
28-
getState: GetState<State>;
29-
dispatch: Dispatch<R, State>;
27+
export interface Store<S, R = Reducer<S>> {
28+
getState: GetState<S>;
29+
dispatch: Dispatch<R, S>;
3030
subscribe(listener: Listener): Unsubscribe;
31-
addMiddleware<R2>(...middlewares: Middleware<State, R, R2>[]): Store<State, R | R2>;
31+
addMiddleware<R2>(...middlewares: Middleware<S, R, R2>[]): Store<S, R | R2>;
3232
}

0 commit comments

Comments
 (0)