File tree Expand file tree Collapse file tree 4 files changed +18
-30
lines changed Expand file tree Collapse file tree 4 files changed +18
-30
lines changed Original file line number Diff line number Diff line change 1
1
import styles from './__name__.module.scss' ;
2
2
3
3
import * as React from 'react' ;
4
- import { connect , DispatchProp } from 'react-redux' ;
4
+ import { connect } from 'react-redux' ;
5
5
6
6
interface IProps { }
7
7
interface IState { }
8
+ interface IRouteParams { }
8
9
interface IStateToProps { }
9
10
10
11
const mapStateToProps = ( state : IStore , ownProps : IProps ) : IStateToProps => ( { } ) ;
11
12
12
- class __name__ extends React . Component < IProps & IStateToProps & DispatchProp < IAction < any > > , IState > {
13
+ class __name__ extends React . Component < IProps & IStateToProps & ReduxProps < any , IRouteParams > , IState > {
13
14
14
15
// public static defaultProps: Partial<IProps> = {};
15
16
Original file line number Diff line number Diff line change 1
1
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel' ;
2
2
import __store__Effect from './__store__Effect' ;
3
3
4
- export type __store__ActionUnion = void | HttpErrorResponseModel | __model__ResponseModel ;
4
+ type ActionUnion = void | HttpErrorResponseModel | __model__ResponseModel ;
5
5
6
6
export default class __store__Action {
7
7
public static readonly REQUEST___model__ ( constantCase ) : string = '__store__Action.REQUEST___model__(constantCase)' ;
8
8
public static readonly REQUEST___model__ ( constantCase ) _FINISHED : string = '__store__Action.REQUEST___model__(constantCase)_FINISHED' ;
9
9
10
10
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
+ } ;
12
14
}
13
15
14
16
public static request__model__Alt ( ) : any {
15
- return async ( dispatch : ReduxDispatch < __store__ActionUnion > , getState : ( ) => IStore ) => {
17
+ return async ( dispatch : ReduxDispatch < ActionUnion > , getState : ( ) => IStore ) => {
16
18
dispatch ( { type : __store__Action . REQUEST___model__ ( constantCase ) } ) ;
17
19
18
- const model : __model__ResponseModel | HttpErrorResponseModel = await __store__Effects . request__model__ ( ) ;
20
+ const model : __model__ResponseModel | HttpErrorResponseModel = await __store__Effect . request__model__ ( ) ;
19
21
20
22
dispatch ( {
21
23
type : __store__Action . REQUEST___model__ ( constantCase ) _FINISHED ,
Original file line number Diff line number Diff line change 1
- import { AxiosResponse } from 'axios' ;
2
1
import environment from 'environment' ;
3
2
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel' ;
4
3
5
4
export default class __store__Effect {
6
- private static _http = new HttpUtility ( ) ;
7
5
8
6
public static async request__model__ ( ) : Promise < __model__ResponseModel | HttpErrorResponseModel > {
9
7
const endpoint : string = environment . api . __model__ ( camelCase ) ;
10
- const response : AxiosResponse | HttpErrorResponseModel = await __store__Effect . _http . get ( endpoint ) ;
11
8
12
- if ( response instanceof HttpErrorResponseModel ) {
13
- return response ;
14
- }
9
+ return EffectUtility . getToModel < __model__ResponseModel > ( __model__ResponseModel , endpoint ) ;
15
10
16
- return new __model__ResponseModel ( response . data ) ;
17
11
}
18
12
}
Original file line number Diff line number Diff line change 1
1
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' ;
3
3
import __model__ResponseModel from './models/__model__(kebabCase)/__model__ResponseModel' ;
4
4
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 = {
7
7
__model__ ( camelCase ) : null ,
8
8
} ;
9
9
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
+ } ;
24
15
}
25
16
}
You can’t perform that action at this time.
0 commit comments