Skip to content

Commit 110b2f7

Browse files
author
Robert S
committed
update templates
1 parent 19c431f commit 110b2f7

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

tools/templates/react/connected-component/__name__.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import styles from './__name__.module.scss';
22

33
import * as React from 'react';
4-
import {connect, DispatchProp} from 'react-redux';
4+
import {connect} from 'react-redux';
55

66
interface IProps {}
77
interface IState {}
8+
interface IRouteParams {}
89
interface IStateToProps {}
910

1011
const mapStateToProps = (state: IStore, ownProps: IProps): IStateToProps => ({});
1112

12-
class __name__ extends React.Component<IProps & IStateToProps & DispatchProp<IAction<any>>, IState> {
13+
class __name__ extends React.Component<IProps & IStateToProps & ReduxProps<any, IRouteParams>, IState> {
1314

1415
// public static defaultProps: Partial<IProps> = {};
1516

tools/templates/react/redux-store/__store__Action.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel';
22
import __store__Effect from './__store__Effect';
33

4-
export type __store__ActionUnion = void | HttpErrorResponseModel | __model__ResponseModel;
4+
type ActionUnion = void | HttpErrorResponseModel | __model__ResponseModel;
55

66
export default class __store__Action {
77
public static readonly REQUEST___model__(constantCase): string = '__store__Action.REQUEST___model__(constantCase)';
88
public static readonly REQUEST___model__(constantCase)_FINISHED: string = '__store__Action.REQUEST___model__(constantCase)_FINISHED';
99

1010
public static request__model__(): any {
11-
return ActionUtility.createThunkEffect<__model__ResponseModel>(__store__Action.REQUEST___model__(constantCase), __store__Effects.request__model__);
11+
return async (dispatch: ReduxDispatch<ActionUnion>, getState: () => IStore) => {
12+
await ActionUtility.createThunkEffect<__model__ResponseModel>(dispatch, __store__Action.REQUEST___model__(constantCase), __store__Effect.request__model__);
13+
};
1214
}
1315

1416
public static request__model__Alt(): any {
15-
return async (dispatch: ReduxDispatch<__store__ActionUnion>, getState: () => IStore) => {
17+
return async (dispatch: ReduxDispatch<ActionUnion>, getState: () => IStore) => {
1618
dispatch({type: __store__Action.REQUEST___model__(constantCase)});
1719

18-
const model: __model__ResponseModel | HttpErrorResponseModel = await __store__Effects.request__model__();
20+
const model: __model__ResponseModel | HttpErrorResponseModel = await __store__Effect.request__model__();
1921

2022
dispatch({
2123
type: __store__Action.REQUEST___model__(constantCase)_FINISHED,
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import {AxiosResponse} from 'axios';
21
import environment from 'environment';
32
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel';
43

54
export default class __store__Effect {
6-
private static _http = new HttpUtility();
75

86
public static async request__model__(): Promise<__model__ResponseModel | HttpErrorResponseModel> {
97
const endpoint: string = environment.api.__model__(camelCase);
10-
const response: AxiosResponse | HttpErrorResponseModel = await __store__Effect._http.get(endpoint);
118

12-
if (response instanceof HttpErrorResponseModel) {
13-
return response;
14-
}
9+
return EffectUtility.getToModel<__model__ResponseModel>(__model__ResponseModel, endpoint);
1510

16-
return new __model__ResponseModel(response.data);
1711
}
1812
}
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
import I__store__State from './models/I__store__State';
2-
import __store__Action, {__store__ActionUnion} from './__store__Action';
2+
import __store__Action from './__store__Action';
33
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel';
44

5-
export default class __store__Reducer {
6-
public static readonly initialState: I__store__State = {
5+
export default class __store__Reducer extends BaseReducer<I__store__State> {
6+
public readonly initialState: I__store__State = {
77
__model__(camelCase): null,
88
};
99

10-
public static reducer(state: I__store__State = __store__Reducer.initialState, action: IAction<__store__ActionUnion>): I__store__State {
11-
if (action.error) {
12-
return state;
13-
}
14-
15-
switch (action.type) {
16-
case __store__Action.REQUEST___model__(constantCase)_FINISHED:
17-
return {
18-
...state,
19-
__model__(camelCase): action.payload as __model__ResponseModel,
20-
};
21-
default:
22-
return state;
23-
}
10+
public [__store__Action.REQUEST___model__(constantCase)_FINISHED](state: I__store__State, action: IAction<__model__ResponseModel>): I__store__State {
11+
return {
12+
...state,
13+
__model__(camelCase): action.payload!,
14+
};
2415
}
2516
}

0 commit comments

Comments
 (0)