Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@praveenpuglia
Last active April 25, 2018 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveenpuglia/12b445b9f5b1ea8f160c83ff64d30164 to your computer and use it in GitHub Desktop.
Save praveenpuglia/12b445b9f5b1ea8f160c83ff64d30164 to your computer and use it in GitHub Desktop.
Access state inside an ngrx effect
// In the Effect's constructor, inject store.
constructor(private store: Store<AppState>)
...
@Effect()
fetchUserProfile$: Observable<Action> = this.actions$.pipe(
ofType<FetchUserProfile>(UserActionTypes.FETCH_USER_PROFILE),
withLatestFrom(this.store),
mergeMap(([action, appState]) => {
return this.http
.get(
`${environment.apiUrl}/api/user/${appState.user.id}`
)
.pipe(
map((response: any) => {
return new FetchUserProfileSuccess(response.data);
}),
catchError(error => of(new FetchUserProfileFailure(error)))
);
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment