Refactor store to accept state as part of params
The old code was returning a fn because TypeScript could not figure out
generic type parameters when params was an object like:
interface Params<State> {
a: Reducer<State>
b: Partial<State>
}
function test<State>(params: Params<State>) {
// ...
}
This commit is contained in:
parent
5623001497
commit
a8d603dd59
@ -74,7 +74,7 @@ describe('CRUD', () => {
|
||||
},
|
||||
})
|
||||
function getStore() {
|
||||
return test.createStore({reducer})()
|
||||
return test.createStore({reducer})
|
||||
}
|
||||
|
||||
type Store = ReturnType<typeof getStore>
|
||||
|
||||
@ -62,12 +62,13 @@ export class TestUtils {
|
||||
let store = this.createStore({
|
||||
reducer: this.combineReducers(reducers),
|
||||
extraMiddleware: [waitMiddleware.handle],
|
||||
})()
|
||||
})
|
||||
|
||||
const withState = (state: DeepPartial<State>) => {
|
||||
const withState = (state: Partial<State>) => {
|
||||
store = this.createStore({
|
||||
reducer: this.combineReducers(reducers),
|
||||
})(state)
|
||||
state,
|
||||
})
|
||||
|
||||
return {withComponent}
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ describe('createActions', () => {
|
||||
})
|
||||
|
||||
const reducer = combineReducers({handler, mapping})
|
||||
const store = createStore({reducer})()
|
||||
const store = createStore({reducer})
|
||||
|
||||
return {client, store}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Action, applyMiddleware, createStore as create, DeepPartial, Middleware, Reducer } from 'redux'
|
||||
import { Action, applyMiddleware, createStore as create, Middleware, Reducer } from 'redux'
|
||||
import { PromiseMiddleware, ReduxLogger } from '../middleware'
|
||||
|
||||
export interface CreateStoreParams<State, A extends Action> {
|
||||
@ -25,9 +25,9 @@ export function createStore<State, A extends Action>(
|
||||
if (params.extraMiddleware) {
|
||||
middleware.push(...params.extraMiddleware)
|
||||
}
|
||||
return (state?: DeepPartial<State>) => create(
|
||||
return create(
|
||||
params.reducer,
|
||||
state,
|
||||
params.state,
|
||||
applyMiddleware(...middleware),
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user