Skip to content

Commit da09f5a

Browse files
author
Péter Hauszknecht
committed
simplifies
1 parent 018ceee commit da09f5a

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/store/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Store<State, R = Reducer<State>> implements IStore<State, R
99
static thunk = thunk;
1010

1111
private state: State;
12-
private listeners: Function[] = [];
12+
private listeners: Listener[] = [];
1313

1414
constructor(initialState: State) {
1515
this.state = initialState;
@@ -35,11 +35,7 @@ export default class Store<State, R = Reducer<State>> implements IStore<State, R
3535
addMiddleware = <R2>(...middlewares: Middleware<State, R, R2>[]): Store<State, R | R2> => {
3636
if (middlewares.some(middleware => typeof middleware !== 'function'))
3737
throw new Error('Middleware is not a function: addMiddleware takes only middlewares as functions.');
38-
middlewares.forEach(middleware => {
39-
const prevDispatch = this.dispatch;
40-
const dispatch = reducer => middleware(this)(prevDispatch)(reducer);
41-
this.dispatch = dispatch;
42-
});
38+
middlewares.forEach(middleware => (this.dispatch = middleware(this)(this.dispatch) as any));
4339
return this;
4440
};
4541
}

src/store/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface Middleware<State, R1, R2> {
2222
(store: Store<State, R1>): {
2323
(next: Dispatch<R1>): {
2424
(reducer: R2): any;
25-
}
25+
};
2626
};
2727
}
2828

0 commit comments

Comments
 (0)