Skip to content

Commit b7aec2c

Browse files
committed
fix: redux utils
Signed-off-by: Vitor Hugo Salgado <[email protected]>
1 parent 8f5bd90 commit b7aec2c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/utils/redux/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import { Action } from '@app/store'
22

33
export const applyReducers =
4-
<T>(...reducers: Array<(state: T, action: Action<never>) => T>) =>
5-
(state: T, action: Action<never>): T =>
6-
reducers.reduce((a: any, b: any) => a(b(state, action), action)) as any
4+
<T>(...reducers: Array<(state: T, action: Action<any>) => T>) =>
5+
(state: T, action: Action<any>): T => {
6+
let st = state
7+
8+
for (const reducer of reducers) {
9+
st = reducer(st, action)
10+
}
11+
12+
return st
13+
}
714

815
export const actionIs =
916
(type: string) =>
10-
(action: Action<never>): boolean =>
17+
(action: Action<any>): boolean =>
1118
type === action?.type
1219

1320
export const onlyWhen =
14-
(predicate: (action: Action<never>) => boolean, defaultState: any = {}) =>
15-
(reducer: (state: any, action: Action<never>) => any) =>
16-
(state: any = {}, action: Action<never>): any => {
17-
if (typeof state === 'undefined') {
21+
(predicate: (action: Action<any>) => boolean, defaultState: any = {}) =>
22+
(reducer: (state: any, action: Action<any>) => any) =>
23+
(state: any, action: Action<any>): any => {
24+
if (state === null || typeof state === 'undefined') {
1825
return defaultState
1926
}
2027

0 commit comments

Comments
 (0)