2018-04-30 11:50:47 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
import { Effect, Actions } from '@ngrx/effects';
|
|
|
|
import { Action } from '@ngrx/store';
|
|
|
|
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
import { of } from 'rxjs/observable/of';
|
|
|
|
|
|
|
|
import 'rxjs/add/operator/catch';
|
|
|
|
import 'rxjs/add/operator/do';
|
|
|
|
import 'rxjs/add/operator/exhaustMap';
|
|
|
|
import 'rxjs/add/operator/map';
|
|
|
|
import 'rxjs/add/operator/take';
|
|
|
|
|
|
|
|
import { MemberService } from '../../service/member.service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Modify,
|
|
|
|
ModifySuccess,
|
|
|
|
ModifyFailure,
|
|
|
|
ActionType
|
|
|
|
} from './modify.action';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private memberService: MemberService,
|
|
|
|
private router: Router
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
modify$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.Modify)
|
|
|
|
.map((action: Modify) => action.payload)
|
|
|
|
.exhaustMap(payload =>
|
|
|
|
this.memberService
|
2018-04-30 12:08:01 +00:00
|
|
|
.modify(payload)
|
2018-04-30 11:50:47 +00:00
|
|
|
.map(_member => new ModifySuccess(_member))
|
|
|
|
.catch(error => of(new ModifyFailure(error)))
|
|
|
|
);
|
|
|
|
|
|
|
|
// @Effect({ dispatch: false })
|
|
|
|
// modifySuccess$ = this.actions$
|
|
|
|
// .ofType(ActionType.ModifySuccess)
|
|
|
|
// .do(() => this.router.navigate(['/']));
|
|
|
|
|
|
|
|
}
|