Skip to content

Instantly share code, notes, and snippets.

@bertrandg
Last active February 14, 2017 16:06
Show Gist options
  • Save bertrandg/6207c52d8d58d4ca6f2ed924131a65c9 to your computer and use it in GitHub Desktop.
Save bertrandg/6207c52d8d58d4ca6f2ed924131a65c9 to your computer and use it in GitHub Desktop.
ngrx/effects simple example
@Effect() actionX$ = this.updates$
.ofType('ACTION_X')
.map(toPayload)
.switchMap(payload => this.api.callApiX(payload)
.map(data => ({type: 'ACTION_X_SUCCESS', payload: data}))
.catch(err => Observable.of({type: 'ACTION_X_FAIL', payload: err}))
);
@Effect() actionY$ = this.updates$
.ofType('ACTION_Y')
.map(toPayload)
.switchMap(payload => this.api.callApiY(payload)
.map(data => ({type: 'ACTION_Y_SUCCESS', payload: data}))
.catch(err => Observable.of({type: 'ACTION_Y_FAIL', payload: err}))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment