Skip to content

Commit

Permalink
fix replaceReducer type
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed Aug 16, 2019
1 parent 9c9a4d2 commit 6b76c98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ export interface Store<S = any, A extends Action = AnyAction> {
*
* @param nextReducer The reducer for the store to use instead.
*/
replaceReducer(nextReducer: Reducer<S, A>): void
replaceReducer<NewState = S, NewActions extends A = A>(
nextReducer: Reducer<NewState, NewActions>
): Store<NewState, NewActions>

/**
* Interoperability point for observable/reactive libraries.
Expand Down Expand Up @@ -667,3 +669,9 @@ export function compose<R>(
): (...args: any[]) => R

export function compose<R>(...funcs: Function[]): (...args: any[]) => R

export const __DO_NOT_USE__ActionTypes: {
INIT: string
REPLACE: string
PROBE_UNKNOWN_ACTION: () => string
}
4 changes: 3 additions & 1 deletion src/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
// will receive the previous state. This effectively populates
// the new state tree with any relevant data from the old one.
dispatch({ type: ActionTypes.REPLACE })
return store
}

/**
Expand Down Expand Up @@ -284,11 +285,12 @@ export default function createStore(reducer, preloadedState, enhancer) {
// the initial state tree.
dispatch({ type: ActionTypes.INIT })

return {
const store = {
dispatch,
subscribe,
getState,
replaceReducer,
[$$observable]: observable
}
return store
}

0 comments on commit 6b76c98

Please sign in to comment.