How to access the value of the first . map()?

Asked

Viewed 35 times

1

I’m doing an introduction to Redux with angular 4, and when I was doing a @Effect() I came across the following question:

@Effect()
private newUser = this.actions$
    .ofType(UserActions.NEW_USER)
    .map((action: UserActions.NewUser) => action.payload)
    .switchMap((userData: UserCreation) => {
        const headers = new HttpHeaders().set('Content-Type', 'application/json');
        return this.http.post<User>(this.urlService.postNewUserUrl(), userData, { headers, observe: 'body' });
    })
    .map(user => {
        return {type: AuthActions.TRY_SIGNIN, payload: -->{email: userData.email, userData.password}}<--
    });

How can I access the issued value of the first . map() to be used by the following operators? In this case I want to use what was returned to switchMap() through the first map().

1 answer

1

I decided as follows:

@Effect()
private newUser = this.actions$
    .ofType(UserActions.NEW_USER)
    .map((action: UserActions.NewUser) => action.payload)
    .switchMap((userData: UserCreation) => {
        const headers = new HttpHeaders().set('Content-Type', 'application/json');
        return this.http.post<User>(this.urlService.postNewUserUrl(), userData, { headers, observe: 'body' })
        .map(user => {
            return {type: AuthActions.TRY_SIGNIN, payload: {email: userData.email, password: userData.password} };
        });
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.