[inulax] 修复middleware(...) is not a function
This commit is contained in:
parent
3fb6652607
commit
3019fa5581
|
@ -27,12 +27,12 @@ export {
|
|||
createDispatchHook,
|
||||
} from './reduxReact';
|
||||
|
||||
export type ReduxStoreHandler = {
|
||||
reducer: (state: any, action: { type: string }) => any;
|
||||
dispatch: (action: { type: string }) => void;
|
||||
getState: () => any;
|
||||
subscribe: (listener: () => void) => () => void;
|
||||
replaceReducer: (reducer: (state: any, action: { type: string }) => any) => void;
|
||||
export type ReduxStoreHandler<T = any> = {
|
||||
reducer(state: T, action: { type: string }): any;
|
||||
dispatch(action: { type: string }): void;
|
||||
getState(): T;
|
||||
subscribe(listener: () => void): () => void;
|
||||
replaceReducer(reducer: (state: T, action: { type: string }) => any): void;
|
||||
};
|
||||
|
||||
export type ReduxAction = {
|
||||
|
@ -53,6 +53,9 @@ export type ReduxMiddleware = (
|
|||
|
||||
type Reducer = (state: any, action: ReduxAction) => any;
|
||||
|
||||
type StoreCreator = (reducer: Reducer, preloadedState?: any) => ReduxStoreHandler
|
||||
type StoreEnhancer = (next: StoreCreator) => StoreCreator
|
||||
|
||||
function mergeData(state, data) {
|
||||
if (!data) {
|
||||
state.stateWrapper = data;
|
||||
|
@ -87,7 +90,7 @@ function mergeData(state, data) {
|
|||
state.stateWrapper = data;
|
||||
}
|
||||
|
||||
export function createStore(reducer: Reducer, preloadedState?: any, enhancers?): ReduxStoreHandler {
|
||||
export function createStore(reducer: Reducer, preloadedState?: any, enhancers?: StoreEnhancer): ReduxStoreHandler {
|
||||
const store = createStoreX({
|
||||
id: 'defaultStore',
|
||||
state: { stateWrapper: preloadedState },
|
||||
|
@ -150,19 +153,23 @@ export function combineReducers(reducers: { [key: string]: Reducer }): Reducer {
|
|||
};
|
||||
}
|
||||
|
||||
function applyMiddlewares(store: ReduxStoreHandler, middlewares: ReduxMiddleware[]): void {
|
||||
middlewares = middlewares.slice();
|
||||
middlewares.reverse();
|
||||
let dispatch = store.dispatch;
|
||||
middlewares.forEach(middleware => {
|
||||
dispatch = middleware(store)(dispatch);
|
||||
});
|
||||
store.dispatch = dispatch;
|
||||
function applyMiddlewares(createStore: StoreCreator, middlewares: ReduxMiddleware[]): StoreCreator {
|
||||
return (reducer, preloadedState) => {
|
||||
middlewares = middlewares.slice();
|
||||
middlewares.reverse();
|
||||
const storeObj = createStore(reducer, preloadedState);
|
||||
let dispatch = storeObj.dispatch;
|
||||
middlewares.forEach(middleware => {
|
||||
dispatch = middleware(storeObj)(dispatch);
|
||||
});
|
||||
storeObj.dispatch = dispatch;
|
||||
return storeObj;
|
||||
};
|
||||
}
|
||||
|
||||
export function applyMiddleware(...middlewares: ReduxMiddleware[]): (store: ReduxStoreHandler) => void {
|
||||
return store => {
|
||||
return applyMiddlewares(store, middlewares);
|
||||
export function applyMiddleware(...middlewares: ReduxMiddleware[]): (createStore: StoreCreator) => StoreCreator {
|
||||
return createStore => {
|
||||
return applyMiddlewares(createStore, middlewares);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -170,7 +177,7 @@ type ActionCreator = (...params: any[]) => ReduxAction;
|
|||
type ActionCreators = { [key: string]: ActionCreator };
|
||||
export type BoundActionCreator = (...params: any[]) => void;
|
||||
type BoundActionCreators = { [key: string]: BoundActionCreator };
|
||||
type Dispatch = (action) => any;
|
||||
type Dispatch = (action: ReduxAction) => any;
|
||||
|
||||
export function bindActionCreators(actionCreators: ActionCreators, dispatch: Dispatch): BoundActionCreators {
|
||||
const boundActionCreators = {};
|
||||
|
|
|
@ -35,5 +35,5 @@ function createThunkMiddleware(extraArgument?: any): ReduxMiddleware {
|
|||
}
|
||||
|
||||
export const thunk = createThunkMiddleware();
|
||||
// @ts-ignore
|
||||
thunk.withExtraArgument = createThunkMiddleware;
|
||||
|
||||
export const withExtraArgument = createThunkMiddleware;
|
||||
|
|
Loading…
Reference in New Issue