Skip to content

Commit

Permalink
add replaceReducer config
Browse files Browse the repository at this point in the history
  • Loading branch information
chonkybirb-2 committed Apr 14, 2020
1 parent ec3bc3e commit c81c23f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/StoreClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { StoreInterface } from './StoreInterface'
import { StoreState } from './State'
import { MessageHandlers } from './MessageHandler'
import { DevToolsOptions } from './DevTools'
import { StoreReducer } from './Reducer'

// Options passed to createStoreClass()
export interface CreateStoreClassOptions<T extends StoreInterface> {
initialState: StoreState<T>
messageHandlers: MessageHandlers<T>
middleware?: Middleware<T> | Middleware<T>[]
devToolsOptions?: DevToolsOptions<T>
replaceReducer?: (rootReducer: StoreReducer<T>) => StoreReducer<T>
}

// Defines Shape and Behaviour of a Store.
Expand Down
5 changes: 4 additions & 1 deletion src/StoreInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export function createStoreInstance<T extends StoreInterface>(

// The Reducer of this store needs access to the dispatch, as individual messageHandlers might want to
// dispatch additional messages.
const reducer = createReducer(options, storeInstance)
let reducer = createReducer(options, storeInstance)
if (options.replaceReducer) {
reducer = options.replaceReducer(reducer)
}

// Build up the chain of middlewares
const executeMiddleware = createExecuteMiddleware(
Expand Down

0 comments on commit c81c23f

Please sign in to comment.