member_webapp/@overflow/sensor/store/regist/regist.effect.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-04-06 11:02:18 +00:00
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } 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';
2018-05-24 06:44:13 +00:00
import { RPCClientError } from '@loafer/ng-rpc';
2018-04-06 11:02:18 +00:00
2018-05-02 08:32:16 +00:00
import { Sensor } from '@overflow/commons-typescript/model/sensor';
2018-04-06 11:02:18 +00:00
import { SensorService } from '../../service/sensor.service';
import {
Regist,
RegistSuccess,
RegistFailure,
ActionType,
} from './regist.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private service: SensorService,
private router: Router
) { }
@Effect()
regist$: Observable<Action> = this.actions$
.ofType(ActionType.Regist)
.map((action: Regist) => action.payload)
.switchMap(payload => this.service.registSensorConfig(payload.sensor, payload.sensorItems))
.map(list => {
return new RegistSuccess(list);
})
.catch((error: RPCClientError) => {
return of(new RegistFailure(error));
});
}