//app.effect.ts import { Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import {addCityToIndex, returnCityToIndex} from './reducers/form.reducer'; import { map } from 'rxjs/operators'; import { HttpService } from './services/http.service'; @Injectable() export class AppEffects { effect$ = createEffect(() => this.actions$.pipe( ofType(addCityToIndex), map(data => returnCityToIndex(data)) ), {}); constructor(private actions$: Actions, private http: HttpService) {} }Necesito actualizar los datos, que tengo en addCityToIndex (matriz) a través del servicio http: obtener la propiedad del elemento de la matriz, realizar una solicitud al servicio, actualizar el elemento y pasar una nueva matriz a returnCityToIndex.
¿Es posible y si está bien, entonces cómo transformar los datos dentro del efecto ngrx?
Basado en documentación
Puede usar una action para activar una solicitud y devolver otra action que actualizará su estado, y su componente recibirá los nuevos datos en el selector cuando se actualicen los datos.
Ex:
login$ = createEffect(() => this.actions$.pipe( ofType(LoginPageActions.login), exhaustMap(action => this.authService.login(action.credentials).pipe( map(user => AuthApiActions.loginSuccess({ user })), catchError(error => of(AuthApiActions.loginFailure({ error }))) ) ) ) );