Skip to content

Commit

Permalink
change reducer type validation place (#4452)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Dorr <git@timdorr.com>
  • Loading branch information
Ahmed-Hakeem and timdorr authored Dec 15, 2022
1 parent a075431 commit fbfe514
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export default function createStore<
preloadedState?: PreloadedState<S> | StoreEnhancer<Ext, StateExt>,
enhancer?: StoreEnhancer<Ext, StateExt>
): Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext {
if (typeof reducer !== 'function') {
throw new Error(
`Expected the root reducer to be a function. Instead, received: '${kindOf(
reducer
)}'`
)
}

if (
(typeof preloadedState === 'function' && typeof enhancer === 'function') ||
(typeof enhancer === 'function' && typeof arguments[3] === 'function')
Expand Down Expand Up @@ -99,14 +107,6 @@ export default function createStore<
) as Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext
}

if (typeof reducer !== 'function') {
throw new Error(
`Expected the root reducer to be a function. Instead, received: '${kindOf(
reducer
)}'`
)
}

let currentReducer = reducer
let currentState = preloadedState as S
let currentListeners: (() => void)[] | null = []
Expand Down

0 comments on commit fbfe514

Please sign in to comment.