buildCreateStore => ts
This commit is contained in:
parent
beae30d091
commit
4754fb2377
@ -1,17 +0,0 @@
|
||||
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
|
||||
|
||||
export default function buildCreateStore( reducer, initial, middleware,
|
||||
actions ) {
|
||||
return () => {
|
||||
const store = reduxCreateStore( reducer, initial,
|
||||
applyMiddleware( middleware)
|
||||
);
|
||||
for ( let a in actions ) {
|
||||
store.dispatch[a] = (...args) => {
|
||||
store.dispatch(actions[a](...args))
|
||||
};
|
||||
}
|
||||
|
||||
return store;
|
||||
}
|
||||
};
|
31
src/buildCreateStore/index.ts
Normal file
31
src/buildCreateStore/index.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import {
|
||||
createStore as reduxCreateStore,
|
||||
applyMiddleware,
|
||||
Middleware,
|
||||
Reducer,
|
||||
} from 'redux';
|
||||
import { ActionCreator, Dictionary } from '../types';
|
||||
|
||||
function buildCreateStore<S>(
|
||||
reducer: Reducer<S>,
|
||||
initial: S,
|
||||
middleware: Middleware,
|
||||
actions: Dictionary<ActionCreator>,
|
||||
) {
|
||||
return () => {
|
||||
const store = reduxCreateStore(
|
||||
reducer,
|
||||
initial,
|
||||
applyMiddleware(middleware),
|
||||
);
|
||||
for (let a in actions) {
|
||||
( store.dispatch as any)[a] = (...args: any[]) => {
|
||||
store.dispatch(actions[a](...args));
|
||||
};
|
||||
}
|
||||
|
||||
return store;
|
||||
};
|
||||
}
|
||||
|
||||
export default buildCreateStore;
|
Loading…
Reference in New Issue
Block a user