@@ -5,7 +5,6 @@ import UserAction from '../../stores/user/UserAction';
5
5
import MetaAction from '../../stores/meta/MetaAction' ;
6
6
import IStore from '../../stores/IStore' ;
7
7
import { Dispatch } from 'redux' ;
8
- import IMetaReducerState from '../../stores/meta/IMetaReducerState' ;
9
8
import IUserReducerState from '../../stores/user/IUserReducerState' ;
10
9
import GenericModalAsync from '../modals/GenericModalAsync' ;
11
10
import ModalAction from '../../stores/modal/ModalAction' ;
@@ -19,29 +18,23 @@ interface IStateToProps {
19
18
readonly user : IUserReducerState ;
20
19
}
21
20
interface IDispatchToProps {
22
- historyPush : ( route : string ) => void ;
23
- loadUser : ( ) => void ;
24
- setMeta : ( meta : IMetaReducerState ) => void ;
25
- addModal : ( modal : JSX . Element ) => void ;
21
+ dispatch : ( action : IAction < any > ) => void ;
26
22
}
27
23
28
24
const mapStateToProps = ( state : IStore ) : IStateToProps => ( {
29
25
user : state . userReducer ,
30
26
} ) ;
31
27
const mapDispatchToProps = ( dispatch : Dispatch < IAction < any > > ) : IDispatchToProps => ( {
32
- historyPush : ( route : string ) => dispatch ( push ( route ) ) ,
33
- loadUser : ( ) => dispatch ( UserAction . loadUser ( ) ) ,
34
- setMeta : ( meta : IMetaReducerState ) => dispatch ( MetaAction . setMeta ( meta ) ) ,
35
- addModal : ( modal : JSX . Element ) => dispatch ( ModalAction . addModal ( modal ) ) ,
28
+ dispatch,
36
29
} ) ;
37
30
38
31
class Home extends React . Component < IStateToProps & IDispatchToProps & IProps , IState > {
39
32
40
33
public componentWillMount ( ) : void {
41
- this . props . setMeta ( {
34
+ this . props . dispatch ( MetaAction . setMeta ( {
42
35
title : 'Home Page' ,
43
36
description : 'This is the Home Page' ,
44
- } ) ;
37
+ } ) ) ;
45
38
}
46
39
47
40
public render ( ) : JSX . Element {
@@ -59,7 +52,7 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
59
52
< p >
60
53
< button
61
54
className = "btn btn-lg btn-success"
62
- onClick = { this . props . loadUser }
55
+ onClick = { this . _loadUser }
63
56
>
64
57
{ 'Load Another User' }
65
58
</ button >
@@ -74,10 +67,16 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
74
67
) ;
75
68
}
76
69
70
+ private _loadUser = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
71
+ event . preventDefault ( ) ;
72
+
73
+ this . props . dispatch ( UserAction . loadUser ( ) ) ;
74
+ }
75
+
77
76
private _onClickPushExample = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
78
77
event . preventDefault ( ) ;
79
78
80
- this . props . historyPush ( '/About' ) ;
79
+ this . props . dispatch ( push ( '/About' ) ) ;
81
80
}
82
81
83
82
private _onClickOpenModal = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
@@ -97,7 +96,7 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
97
96
/>
98
97
) ;
99
98
100
- this . props . addModal ( genericModal ) ;
99
+ this . props . dispatch ( ModalAction . addModal ( genericModal ) ) ;
101
100
}
102
101
103
102
private _onAccept = ( modalProps : GenericModalProps ) : void => {
@@ -112,15 +111,15 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
112
111
/>
113
112
) ;
114
113
115
- this . props . addModal ( genericModal ) ;
114
+ this . props . dispatch ( ModalAction . addModal ( genericModal ) ) ;
116
115
}
117
116
118
117
private _onClickFormModal = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
119
118
const formModal : JSX . Element = (
120
119
< ExampleFormModalAsync isRequired = { true } />
121
120
) ;
122
121
123
- this . props . addModal ( formModal ) ;
122
+ this . props . dispatch ( ModalAction . addModal ( formModal ) ) ;
124
123
}
125
124
126
125
}
0 commit comments