@@ -5,7 +5,6 @@ import UserAction from '../../stores/user/UserAction';
55import MetaAction from '../../stores/meta/MetaAction' ;
66import IStore from '../../stores/IStore' ;
77import { Dispatch } from 'redux' ;
8- import IMetaReducerState from '../../stores/meta/IMetaReducerState' ;
98import IUserReducerState from '../../stores/user/IUserReducerState' ;
109import GenericModalAsync from '../modals/GenericModalAsync' ;
1110import ModalAction from '../../stores/modal/ModalAction' ;
@@ -19,29 +18,23 @@ interface IStateToProps {
1918 readonly user : IUserReducerState ;
2019}
2120interface 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 ;
2622}
2723
2824const mapStateToProps = ( state : IStore ) : IStateToProps => ( {
2925 user : state . userReducer ,
3026} ) ;
3127const 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,
3629} ) ;
3730
3831class Home extends React . Component < IStateToProps & IDispatchToProps & IProps , IState > {
3932
4033 public componentWillMount ( ) : void {
41- this . props . setMeta ( {
34+ this . props . dispatch ( MetaAction . setMeta ( {
4235 title : 'Home Page' ,
4336 description : 'This is the Home Page' ,
44- } ) ;
37+ } ) ) ;
4538 }
4639
4740 public render ( ) : JSX . Element {
@@ -59,7 +52,7 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
5952 < p >
6053 < button
6154 className = "btn btn-lg btn-success"
62- onClick = { this . props . loadUser }
55+ onClick = { this . _loadUser }
6356 >
6457 { 'Load Another User' }
6558 </ button >
@@ -74,10 +67,16 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
7467 ) ;
7568 }
7669
70+ private _loadUser = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
71+ event . preventDefault ( ) ;
72+
73+ this . props . dispatch ( UserAction . loadUser ( ) ) ;
74+ }
75+
7776 private _onClickPushExample = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
7877 event . preventDefault ( ) ;
7978
80- this . props . historyPush ( '/About' ) ;
79+ this . props . dispatch ( push ( '/About' ) ) ;
8180 }
8281
8382 private _onClickOpenModal = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
@@ -97,7 +96,7 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
9796 />
9897 ) ;
9998
100- this . props . addModal ( genericModal ) ;
99+ this . props . dispatch ( ModalAction . addModal ( genericModal ) ) ;
101100 }
102101
103102 private _onAccept = ( modalProps : GenericModalProps ) : void => {
@@ -112,15 +111,15 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
112111 />
113112 ) ;
114113
115- this . props . addModal ( genericModal ) ;
114+ this . props . dispatch ( ModalAction . addModal ( genericModal ) ) ;
116115 }
117116
118117 private _onClickFormModal = ( event : React . MouseEvent < HTMLButtonElement > ) : void => {
119118 const formModal : JSX . Element = (
120119 < ExampleFormModalAsync isRequired = { true } />
121120 ) ;
122121
123- this . props . addModal ( formModal ) ;
122+ this . props . dispatch ( ModalAction . addModal ( formModal ) ) ;
124123 }
125124
126125}
0 commit comments