Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit 103659b

Browse files
committed
Make mapDispatchToProps only have dispatch
1 parent 04e8b77 commit 103659b

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

src/stores/meta/MetaAction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import IMetaReducerState from './IMetaReducerState';
21
import IAction from '../IAction';
2+
import ITitleDescription from './models/ITitleDescription';
33

44
export default class MetaAction {
55

66
public static readonly SET_META: string = 'MetaAction.SET_META';
77

8-
public static setMeta(meta: IMetaReducerState): IAction<IMetaReducerState> {
8+
public static setMeta(meta: ITitleDescription): IAction<ITitleDescription> {
99
if (global.document) {
1010
global.document.title = meta.title;
1111
}

src/views/about/About.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@ import {connect} from 'react-redux';
33
import MetaAction from '../../stores/meta/MetaAction';
44
import IStore from '../../stores/IStore';
55
import {Dispatch} from 'redux';
6-
import IMetaReducerState from '../../stores/meta/IMetaReducerState';
76
import IAction from '../../stores/IAction';
87

98
interface IState {}
109
interface IProps {}
1110
interface IStateToProps {}
1211
interface IDispatchToProps {
13-
setMeta: (meta: IMetaReducerState) => void;
12+
dispatch: (action: IAction<any>) => void;
1413
}
1514

1615
const mapStateToProps = (state: IStore): IStateToProps => ({});
1716
const mapDispatchToProps = (dispatch: Dispatch<IAction<any>>): IDispatchToProps => ({
18-
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
17+
dispatch,
1918
});
2019

2120
class About extends React.Component<IStateToProps & IDispatchToProps & IProps, IState> {
2221

2322
public componentWillMount(): void {
24-
this.props.setMeta({title: 'About Page'});
23+
this.props.dispatch(MetaAction.setMeta({title: 'About Page'}));
2524
}
2625

2726
public render(): JSX.Element {

src/views/contact/Contact.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import {connect} from 'react-redux';
33
import MetaAction from '../../stores/meta/MetaAction';
44
import {Dispatch} from 'redux';
5-
import IMetaReducerState from '../../stores/meta/IMetaReducerState';
65
import IStore from '../../stores/IStore';
76
import ContactForm from './ContactForm';
87
import IAction from '../../stores/IAction';
@@ -11,18 +10,18 @@ interface IState {}
1110
interface IProps {}
1211
interface IStateToProps {}
1312
interface IDispatchToProps {
14-
setMeta: (meta: IMetaReducerState) => void;
13+
dispatch: (action: IAction<any>) => void;
1514
}
1615

1716
const mapStateToProps = (state: IStore): IStateToProps => ({});
1817
const mapDispatchToProps = (dispatch: Dispatch<IAction<any>>): IDispatchToProps => ({
19-
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
18+
dispatch,
2019
});
2120

2221
class Contact extends React.Component<IStateToProps & IDispatchToProps & IProps, IState> {
2322

2423
public componentWillMount(): void {
25-
this.props.setMeta({title: 'Contact Page'});
24+
this.props.dispatch(MetaAction.setMeta({title: 'Contact Page'}));
2625
}
2726

2827
public render(): JSX.Element {

src/views/errors/NotFound.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
33
import MetaAction from '../../stores/meta/MetaAction';
4-
import IMetaReducerState from '../../stores/meta/IMetaReducerState';
54
import IStore from '../../stores/IStore';
65
import {Dispatch} from 'redux';
76
import IAction from '../../stores/IAction';
@@ -10,18 +9,18 @@ interface IState {}
109
interface IProps {}
1110
interface IStateToProps {}
1211
interface IDispatchToProps {
13-
setMeta: (meta: IMetaReducerState) => void;
12+
dispatch: (action: IAction<any>) => void;
1413
}
1514

1615
const mapStateToProps = (state: IStore): IStateToProps => ({});
1716
const mapDispatchToProps = (dispatch: Dispatch<IAction<any>>): IDispatchToProps => ({
18-
setMeta: (meta: IMetaReducerState) => dispatch(MetaAction.setMeta(meta)),
17+
dispatch,
1918
});
2019

2120
class NotFound extends React.Component<IStateToProps & IDispatchToProps & IProps, IState> {
2221

2322
public componentWillMount(): void {
24-
this.props.setMeta({title: '404 Page Not Found'});
23+
this.props.dispatch(MetaAction.setMeta({title: '404 Page Not Found'}));
2524
}
2625

2726
public render() {

src/views/home/Home.tsx

+15-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import UserAction from '../../stores/user/UserAction';
55
import MetaAction from '../../stores/meta/MetaAction';
66
import IStore from '../../stores/IStore';
77
import {Dispatch} from 'redux';
8-
import IMetaReducerState from '../../stores/meta/IMetaReducerState';
98
import IUserReducerState from '../../stores/user/IUserReducerState';
109
import GenericModalAsync from '../modals/GenericModalAsync';
1110
import ModalAction from '../../stores/modal/ModalAction';
@@ -19,29 +18,23 @@ interface IStateToProps {
1918
readonly user: IUserReducerState;
2019
}
2120
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;
2622
}
2723

2824
const mapStateToProps = (state: IStore): IStateToProps => ({
2925
user: state.userReducer,
3026
});
3127
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,
3629
});
3730

3831
class 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
}

src/views/modals/ModalHub.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ interface IProps {}
99
interface IStateToProps {
1010
readonly currentModal: JSX.Element;
1111
}
12-
interface IDispatchToProps {}
12+
interface IDispatchToProps {
13+
dispatch: (action: IAction<any>) => void;
14+
}
1315

1416
const mapStateToProps = (state: IStore): IStateToProps => ({
1517
currentModal: state.modalReducer.currentModal,
1618
});
17-
const mapDispatchToProps = (dispatch: Dispatch<IAction<any>>): IDispatchToProps => ({});
19+
const mapDispatchToProps = (dispatch: Dispatch<IAction<any>>): IDispatchToProps => ({
20+
dispatch,
21+
});
1822

1923
class ModalHub extends React.Component<IStateToProps & IDispatchToProps & IProps, IState> {
2024

0 commit comments

Comments
 (0)