11import { Injectable } from '@angular/core' ;
22import { Actions , Effect } from '@ngrx/effects' ;
33import { Observable } from 'rxjs/Observable' ;
4- import { of as observableOf } from 'rxjs/observabe /of' ;
4+ import { of as observableOf } from 'rxjs/observable /of' ;
55import { switchMap } from 'rxjs/operators/switchMap' ;
66import { map } from 'rxjs/operators/map' ;
7- import { catch } from 'rxjs/operators/catch ' ;
7+ import { catchError } from 'rxjs/operators/catchError ' ;
88import { HttpErrorResponse } from '@angular/common/http' ;
99import { { { properCase name } } Service } from '{{position "services"}}/{{ kebabCase name }}.service' ;
1010import * as { { camelCase name } } Actions from '{{position "actions"}}/{{ kebabCase name }}.actions' ;
@@ -26,61 +26,77 @@ export class {{ properCase name }}Effects {
2626 ) {
2727 this . load { { titleCase name } } s$ = this . actions$
2828 . ofType ( { { camelCase name } } Actions . LOAD_ { { constantCase name } } S )
29- . switchMap ( ( state : { { camelCase name } } Actions . Load { { titleCase name } } sAction ) => this . { { camelCase name } } Service . load { { titleCase name } } s ( )
30- // If successful, dispatch success action with result
31- . map ( res => new { { camelCase name } } Actions . Load { { titleCase name } } sSuccessAction ( res ) )
32- // If request fails, dispatch failed action
33- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Load { { titleCase name } } sFailAction ( err ) ) )
34- ) ;
29+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Load { { titleCase name } } sAction ) =>
30+ this . { { camelCase name } } Service . load { { titleCase name } } s ( ) . pipe (
31+ // If successful, dispatch success action with result
32+ map ( res => new { { camelCase name } } Actions . Load { { titleCase name } } sSuccessAction ( res ) ) ,
33+ // If request fails, dispatch failed action
34+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Load { { titleCase name } } sFailAction ( err ) ) )
35+ )
36+ ) ) ;
3537
3638 this . add { { titleCase name } } $ = this . actions$
3739 . ofType ( { { camelCase name } } Actions . ADD_ { { constantCase name } } )
38- . switchMap ( ( state : { { camelCase name } } Actions . Add { { titleCase name } } Action ) => this . { { camelCase name } } Service . add { { titleCase name } } ( state . payload )
39- . map ( res => new { { camelCase name } } Actions . Add { { titleCase name } } SuccessAction ( res ) )
40- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Add { { titleCase name } } FailAction ( err ) ) )
41- ) ;
40+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Add { { titleCase name } } Action ) =>
41+ this . { { camelCase name } } Service . add { { titleCase name } } ( state . payload ) . pipe (
42+ map ( res => new { { camelCase name } } Actions . Add { { titleCase name } } SuccessAction ( res ) ) ,
43+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Add { { titleCase name } } FailAction ( err ) ) )
44+ )
45+ ) ) ;
4246
4347 this . add { { titleCase name } } s$ = this . actions$
4448 . ofType ( { { camelCase name } } Actions . ADD_ { { constantCase name } } S )
45- . switchMap ( ( state : { { camelCase name } } Actions . Add { { titleCase name } } sAction ) => this . { { camelCase name } } Service . add { { titleCase name } } s ( state . payload )
46- . map ( res => new { { camelCase name } } Actions . Add { { titleCase name } } sSuccessAction ( res ) )
47- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Add { { titleCase name } } sFailAction ( err ) ) )
48- ) ;
49+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Add { { titleCase name } } sAction ) =>
50+ this . { { camelCase name } } Service . add { { titleCase name } } s ( state . payload ) . pipe (
51+ map ( res => new { { camelCase name } } Actions . Add { { titleCase name } } sSuccessAction ( res ) ) ,
52+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Add { { titleCase name } } sFailAction ( err ) ) )
53+ )
54+ ) ) ;
4955
5056 this . update { { titleCase name } } $ = this . actions$
5157 . ofType ( { { camelCase name } } Actions . UPDATE_ { { constantCase name } } )
52- . switchMap ( ( state : { { camelCase name } } Actions . Update { { titleCase name } } Action ) => this . { { camelCase name } } Service . update { { titleCase name } } ( state . payload )
53- . map ( res => new { { camelCase name } } Actions . Update { { titleCase name } } SuccessAction ( res ) )
54- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Update { { titleCase name } } FailAction ( err ) ) )
55- ) ;
58+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Update { { titleCase name } } Action ) =>
59+ this . { { camelCase name } } Service . update { { titleCase name } } ( state . payload ) . pipe (
60+ map ( res => new { { camelCase name } } Actions . Update { { titleCase name } } SuccessAction ( res ) ) ,
61+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Update { { titleCase name } } FailAction ( err ) ) )
62+ )
63+ ) ) ;
5664
5765 this . update { { titleCase name } } s$ = this . actions$
5866 . ofType ( { { camelCase name } } Actions . UPDATE_ { { constantCase name } } S )
59- . switchMap ( ( state : { { camelCase name } } Actions . Update { { titleCase name } } sAction ) => this . { { camelCase name } } Service . update { { titleCase name } } s ( state . payload )
60- . map ( res => new { { camelCase name } } Actions . Update { { titleCase name } } sSuccessAction ( res ) )
61- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Update { { titleCase name } } sFailAction ( err ) ) )
62- ) ;
67+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Update { { titleCase name } } sAction ) =>
68+ this . { { camelCase name } } Service . update { { titleCase name } } s ( state . payload ) . pipe (
69+ map ( res => new { { camelCase name } } Actions . Update { { titleCase name } } sSuccessAction ( res ) ) ,
70+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Update { { titleCase name } } sFailAction ( err ) ) )
71+ )
72+ ) ) ;
6373
6474 this . delete { { titleCase name } } $ = this . actions$
6575 . ofType ( { { camelCase name } } Actions . DELETE_ { { constantCase name } } )
66- . switchMap ( ( state : { { camelCase name } } Actions . Delete { { titleCase name } } Action ) => this . { { camelCase name } } Service . delete { { titleCase name } } ( state . payload )
67- . map ( res => new { { camelCase name } } Actions . Delete { { titleCase name } } SuccessAction ( res ) )
68- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Delete { { titleCase name } } FailAction ( err ) ) )
69- ) ;
76+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Delete { { titleCase name } } Action ) =>
77+ this . { { camelCase name } } Service . delete { { titleCase name } } ( state . payload ) . pipe (
78+ map ( res => new { { camelCase name } } Actions . Delete { { titleCase name } } SuccessAction ( res ) ) ,
79+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Delete { { titleCase name } } FailAction ( err ) ) )
80+ )
81+ ) ) ;
7082
7183 this . delete { { titleCase name } } s$ = this . actions$
7284 . ofType ( { { camelCase name } } Actions . DELETE_ { { constantCase name } } S )
73- . switchMap ( ( state : { { camelCase name } } Actions . Delete { { titleCase name } } sAction ) => this . { { camelCase name } } Service . delete { { titleCase name } } s ( state . payload )
74- . map ( res => new { { camelCase name } } Actions . Delete { { titleCase name } } sSuccessAction ( res ) )
75- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Delete { { titleCase name } } sFailAction ( err ) ) )
76- ) ;
85+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Delete { { titleCase name } } sAction ) =>
86+ this . { { camelCase name } } Service . delete { { titleCase name } } s ( state . payload ) . pipe (
87+ map ( res => new { { camelCase name } } Actions . Delete { { titleCase name } } sSuccessAction ( res ) ) ,
88+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Delete { { titleCase name } } sFailAction ( err ) ) )
89+ )
90+ ) ) ;
7791
7892 this . clear { { titleCase name } } s$ = this . actions$
7993 . ofType ( { { camelCase name } } Actions . CLEAR_ { { constantCase name } } S )
80- . switchMap ( ( state : { { camelCase name } } Actions . Clear { { titleCase name } } sAction ) => this . { { camelCase name } } Service . clear { { titleCase name } } s ( state . payload )
81- . map ( res => new { { camelCase name } } Actions . Clear { { titleCase name } } sSuccessAction ( res ) )
82- . catch ( ( err : HttpErrorResponse ) => Observable . of ( new { { camelCase name } } Actions . Clear { { titleCase name } } sFailAction ( err ) ) )
83- ) ;
94+ . pipe ( switchMap ( ( state : { { camelCase name } } Actions . Clear { { titleCase name } } sAction ) =>
95+ this . { { camelCase name } } Service . clear { { titleCase name } } s ( state . payload ) . pipe (
96+ map ( res => new { { camelCase name } } Actions . Clear { { titleCase name } } sSuccessAction ( res ) ) ,
97+ catchError ( ( err : HttpErrorResponse ) => observableOf ( new { { camelCase name } } Actions . Clear { { titleCase name } } sFailAction ( err ) ) )
98+ )
99+ ) ) ;
84100 }
85101
86102}
0 commit comments