Skip to content

Commit

Permalink
refactor(dynostore): handle import promises on "withStoreModule"
Browse files Browse the repository at this point in the history
use Promise.all to resolve those promises to let exceptions being handle at once and avoid
"UnhandledPromiseRejectionWarning"

improves #43
  • Loading branch information
aneurysmjs committed Oct 12, 2019
1 parent 57eb087 commit 3e42c20
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/app/store/config/dynoStore/dynoStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let reducerMap: ReducerMap = {

const createRootReducer = (): Reducer => combineReducers(reducerMap);

export const createStore = (enhancer: StoreEnhancer): Store<StoreShape> => {
export const createStore = (enhancer?: StoreEnhancer): Store<StoreShape> => {
store = createReduxStore(createRootReducer(), enhancer);
return store;
};
Expand All @@ -36,12 +36,11 @@ export async function withStoreModule<P>(
reducerImport: Promise<P>,
): Promise<{ default: ComponentType }> {
try {
const module = await componentImport;
const reducer = await reducerImport;
const [module, reducer] = await Promise.all([componentImport, reducerImport]);
injectReducers(reducer);
return module;
} catch (error) {
store.dispatch({ type: '@@DYNO_STORE/ERROR', payload: error });
store.dispatch({ type: '@@DYNO_STORE/ERROR', payload: error.message });
throw error;
}
}
Expand Down

0 comments on commit 3e42c20

Please sign in to comment.