probe detail store
This commit is contained in:
parent
b674002c58
commit
eab08507e0
|
@ -22,4 +22,11 @@ export class ProbeService {
|
|||
public readAllByDomain(domain: Domain): Observable<Probe[]> {
|
||||
return this.rpcService.call<Probe[]>('ProbeService.readAllByDomain', domain);
|
||||
}
|
||||
|
||||
public read(id: string): Observable<Probe> {
|
||||
const param = {
|
||||
id: id,
|
||||
};
|
||||
return this.rpcService.call<Probe>('ProbeService.read', param);
|
||||
}
|
||||
}
|
||||
|
|
37
src/packages/probe/store/detail/detail.action.ts
Normal file
37
src/packages/probe/store/detail/detail.action.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import { Probe } from '../../model';
|
||||
|
||||
|
||||
export enum ActionType {
|
||||
Read = '[probe.detail] Read',
|
||||
ReadSuccess = '[probe.detail] ReadSuccess',
|
||||
ReadFailure = '[probe.detail] ReadFailure',
|
||||
}
|
||||
|
||||
export class Read implements Action {
|
||||
readonly type = ActionType.Read;
|
||||
|
||||
constructor(public payload: {id: string}) {}
|
||||
}
|
||||
|
||||
export class ReadSuccess implements Action {
|
||||
readonly type = ActionType.ReadSuccess;
|
||||
|
||||
constructor(public payload: Probe) {}
|
||||
}
|
||||
|
||||
export class ReadFailure implements Action {
|
||||
readonly type = ActionType.ReadFailure;
|
||||
|
||||
constructor(public payload: ErrorResponse) {}
|
||||
}
|
||||
|
||||
|
||||
export type Actions =
|
||||
| Read
|
||||
| ReadSuccess
|
||||
| ReadFailure
|
||||
;
|
|
@ -1,8 +1,8 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './probe.effect';
|
||||
import { Effects } from './detail.effect';
|
||||
|
||||
describe('NoAuth-Probe.Effects', () => {
|
||||
describe('ProbeDetail.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
49
src/packages/probe/store/detail/detail.effect.ts
Normal file
49
src/packages/probe/store/detail/detail.effect.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
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/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import { Probe } from '../../model';
|
||||
import { ProbeService } from '../../service/probe.service';
|
||||
|
||||
import {
|
||||
Read,
|
||||
ReadFailure,
|
||||
ReadSuccess,
|
||||
ActionType
|
||||
} from './detail.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private probeService: ProbeService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
read$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Read)
|
||||
.map((action: Read) => action.payload)
|
||||
.switchMap(payload => this.probeService.read(payload.id))
|
||||
.map(probe => {
|
||||
return new ReadSuccess(probe);
|
||||
})
|
||||
.catch((error: ErrorResponse) => {
|
||||
return of(new ReadFailure(error));
|
||||
});
|
||||
}
|
50
src/packages/probe/store/detail/detail.reducer.ts
Normal file
50
src/packages/probe/store/detail/detail.reducer.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import {
|
||||
Read,
|
||||
ReadFailure,
|
||||
ReadSuccess,
|
||||
ActionType,
|
||||
Actions,
|
||||
} from './detail.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './detail.state';
|
||||
|
||||
import { Probe } from '../../model';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Read: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: false,
|
||||
probe: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
isPending: false,
|
||||
probe: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
19
src/packages/probe/store/detail/detail.state.ts
Normal file
19
src/packages/probe/store/detail/detail.state.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import { Probe } from '../../model';
|
||||
|
||||
export interface State {
|
||||
error: ErrorResponse | null;
|
||||
isPending: boolean;
|
||||
probe: Probe | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
isPending: false,
|
||||
probe: null,
|
||||
};
|
||||
|
||||
export const getProbe = (state: State) => state.probe;
|
||||
export const getError = (state: State) => state.error;
|
||||
export const isPending = (state: State) => state.isPending;
|
4
src/packages/probe/store/detail/index.ts
Normal file
4
src/packages/probe/store/detail/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export * from './detail.action';
|
||||
export * from './detail.effect';
|
||||
export * from './detail.reducer';
|
||||
export * from './detail.state';
|
|
@ -1,13 +1,17 @@
|
|||
import * as ProbeStore from './list';
|
||||
import * as ProbeListStore from './list';
|
||||
import * as ProbeDetailStore from './detail';
|
||||
|
||||
export interface State {
|
||||
probe: ProbeStore.State;
|
||||
list: ProbeListStore.State;
|
||||
detail: ProbeDetailStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
probe: ProbeStore.reducer,
|
||||
list: ProbeListStore.reducer,
|
||||
detail: ProbeDetailStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ProbeStore.Effects,
|
||||
ProbeListStore.Effects,
|
||||
ProbeDetailStore.Effects,
|
||||
];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export * from './probe.action';
|
||||
export * from './probe.effect';
|
||||
export * from './probe.reducer';
|
||||
export * from './probe.state';
|
||||
export * from './list.action';
|
||||
export * from './list.effect';
|
||||
export * from './list.reducer';
|
||||
export * from './list.state';
|
||||
|
|
15
src/packages/probe/store/list/list.effect.spec.ts
Normal file
15
src/packages/probe/store/list/list.effect.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './list.effect';
|
||||
|
||||
describe('ProbeList.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -26,7 +26,7 @@ import {
|
|||
ReadAllByDomainFailure,
|
||||
ReadAllByDomainSuccess,
|
||||
ActionType
|
||||
} from './probe.action';
|
||||
} from './list.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
|
@ -6,12 +6,12 @@ import {
|
|||
ReadAllByDomainSuccess,
|
||||
ActionType,
|
||||
Actions,
|
||||
} from './probe.action';
|
||||
} from './list.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './probe.state';
|
||||
} from './list.state';
|
||||
|
||||
import { Probe } from '../../model';
|
||||
|
Loading…
Reference in New Issue
Block a user