@@ -5,38 +5,41 @@ import { useAyanami } from './hooks'
55
66type ConnectedComponent < P , S , A > = React . FunctionComponent < Omit < P , keyof S | keyof A > >
77
8- export interface ComponentConnectedWithAyanami < M extends Ayanami < S > , S , P > {
9- ( ) : ConnectedComponent < P , S , ActionMethodOfAyanami < M , S > >
8+ type ConnectComponent < S , A > = < P > ( Component : React . ComponentType < P > ) => ConnectedComponent < P , S , A >
109
11- < MS > ( mapStateToProps : ( state : S ) => MS ) : ConnectedComponent < P , MS , ActionMethodOfAyanami < M , S > >
10+ export interface ComponentConnectedWithAyanami < M extends Ayanami < S > , S > {
11+ ( ) : ConnectComponent < { } , { } >
12+
13+ < MS > ( mapStateToProps : ( state : S ) => MS ) : ConnectComponent < MS , { } >
1214
1315 < MS , MA > (
1416 mapStateToProps : ( state : S ) => MS ,
1517 mapActionsToProps : ( actions : ActionMethodOfAyanami < M , S > ) => MA ,
16- ) : ConnectedComponent < P , MS , MA >
18+ ) : ConnectComponent < MS , MA >
1719
1820 < MA > (
1921 mapStateToProps : null ,
2022 mapActionsToProps : ( actions : ActionMethodOfAyanami < M , S > ) => MA ,
21- ) : ConnectedComponent < P , S , MA >
23+ ) : ConnectComponent < { } , MA >
2224}
2325
24- export function connectAyanami < M extends Ayanami < S > , S > ( AyanamiClass : ConstructorOf < M > ) {
25- return function connectComponent < P > (
26- Component : React . ComponentType < P > ,
27- ) : M extends Ayanami < infer SS >
28- ? ComponentConnectedWithAyanami < M , SS , P >
29- : ComponentConnectedWithAyanami < M , S , P > {
30- return ( (
31- mapStateToProps ?: ( props : S ) => Partial < P > ,
32- mapActionsToProps ?: ( actions : ActionMethodOfAyanami < M , S > ) => Partial < P > ,
33- ) =>
34- function ConnectAyanami ( props : P ) {
26+ export function connectAyanami < M extends Ayanami < S > , S > (
27+ AyanamiClass : ConstructorOf < M > ,
28+ ) : M extends Ayanami < infer SS >
29+ ? ComponentConnectedWithAyanami < M , SS >
30+ : ComponentConnectedWithAyanami < M , S > {
31+ return function connectMap < SP , AP > (
32+ mapStateToProps ?: ( props : S ) => SP ,
33+ mapActionsToProps ?: ( actions : ActionMethodOfAyanami < M , S > ) => AP ,
34+ ) {
35+ return function connectComponent < P > ( Component : React . ComponentType < P > ) {
36+ return function ConnectAyanami ( props : P ) {
3537 const [ state , action ] = useAyanami ( AyanamiClass )
36- const mappedState = mapStateToProps ? mapStateToProps ( state ) : state
37- const mappedAction = mapActionsToProps ? mapActionsToProps ( action as any ) : action
38+ const mappedState = mapStateToProps ? mapStateToProps ( state ) : { }
39+ const mappedAction = mapActionsToProps ? mapActionsToProps ( action as any ) : { }
3840
3941 return < Component { ...mappedState } { ...mappedAction } { ...props } />
40- } ) as any
41- }
42+ }
43+ }
44+ } as any
4245}
0 commit comments