buildCreateStore => ts

This commit is contained in:
Yanick Champoux 2019-10-23 16:02:42 -04:00
parent beae30d091
commit 4754fb2377
2 changed files with 31 additions and 17 deletions

View File

@ -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;
}
};

View 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;