Skip to content

Commit

Permalink
refactor(usealien): reduce AlienResult's boilerplate
Browse files Browse the repository at this point in the history
use Typescript's "Omit" utility type to just use the needed properties from ReduxModule

#43
  • Loading branch information
aneurysmjs committed Dec 6, 2019
1 parent 5ef5c0b commit b6f3a7c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/app/store/config/alienStore/useAlien.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useStore } from 'react-redux';

import { AlienStore } from './alien';

interface ReduxModule<T> {
interface ReduxModule<T = {}> {
reducers: {
[K: string]: Reducer<T>;
};
Expand All @@ -13,14 +13,10 @@ interface ReduxModule<T> {
};
}

interface AlienResult {
actions: {
[K: string]: ActionCreator<AnyAction>;
};
}
type AlienResult = Omit<ReduxModule, 'reducers'>;

interface AlienModule<P> {
getModule: () => Promise<ReduxModule<P>>;
interface AlienModule<T> {
getModule: () => Promise<ReduxModule<T>>;
initialActions?: Array<string>;
}

Expand Down Expand Up @@ -58,7 +54,7 @@ function useAlien<T>(alienModule: AlienModule<T>): AlienResult | null {
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [alienModule]);
}, []);

return errorHandler(alien);
}
Expand Down

0 comments on commit b6f3a7c

Please sign in to comment.