ing
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
||||
import {
|
||||
StoreRouterConnectingModule,
|
||||
RouterStateSerializer,
|
||||
} from '@ngrx/router-store';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './probe.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class ProbeStoreModule { }
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './probe-detail.reducer';
|
||||
export * from './probe-detail.state';
|
||||
@@ -1,31 +0,0 @@
|
||||
import { ActionType, Actions } from '../../entity/probe';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
probeListContainerAdapter
|
||||
} from './probe-detail.state';
|
||||
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Read: {
|
||||
return {
|
||||
...state,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadSuccess: {
|
||||
return probeListContainerAdapter.setOne(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return probeListContainerAdapter.setError(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
||||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { createEntityAdapter, EntityState } from '@loafer/ng-entity';
|
||||
|
||||
export const probeListContainerAdapter = createEntityAdapter<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeListContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './probe-list.reducer';
|
||||
export * from './probe-list.state';
|
||||
@@ -1,31 +0,0 @@
|
||||
import { ActionType, Actions } from '../../entity/probe';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
probeListContainerAdapter
|
||||
} from './probe-list.state';
|
||||
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDomainID: {
|
||||
return {
|
||||
...state,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDSuccess: {
|
||||
return probeListContainerAdapter.setAll(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDFailure: {
|
||||
return probeListContainerAdapter.setError(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
||||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { createEntityAdapter, EntityState } from '@loafer/ng-entity';
|
||||
|
||||
export const probeListContainerAdapter = createEntityAdapter<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeListContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './probe-selector.reducer';
|
||||
export * from './probe-selector.state';
|
||||
@@ -1,31 +0,0 @@
|
||||
import { ActionType, Actions } from '../../entity/probe';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
probeSelectorContainerAdapter
|
||||
} from './probe-selector.state';
|
||||
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDomainID: {
|
||||
return {
|
||||
...state,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDSuccess: {
|
||||
return probeSelectorContainerAdapter.setAll(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDFailure: {
|
||||
return probeSelectorContainerAdapter.setError(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
||||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { createEntityAdapter, EntityState } from '@loafer/ng-entity';
|
||||
|
||||
export const probeSelectorContainerAdapter = createEntityAdapter<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeSelectorContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeSelectorContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './probe.action';
|
||||
export * from './probe.effect';
|
||||
@@ -1,83 +0,0 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByDomainID = '[probe.list] ReadAllByDomainID',
|
||||
ReadAllByDomainIDSuccess = '[probe.list] ReadAllByDomainIDSuccess',
|
||||
ReadAllByDomainIDFailure = '[probe.list] ReadAllByDomainIDFailure',
|
||||
|
||||
Read = '[probe.detail] Read',
|
||||
ReadSuccess = '[probe.detail] ReadSuccess',
|
||||
ReadFailure = '[probe.detail] ReadFailure',
|
||||
|
||||
Modify = '[probe.detail] Modify',
|
||||
ModifySuccess = '[probe.detail] ModifySuccess',
|
||||
ModifyFailure = '[probe.detail] ModifyFailure',
|
||||
}
|
||||
|
||||
export class ReadAllByDomainID implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainID;
|
||||
|
||||
constructor(public payload: number) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDomainIDSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainIDSuccess;
|
||||
|
||||
constructor(public payload: ProbeHost[]) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDomainIDFailure implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainIDFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export class Read implements Action {
|
||||
readonly type = ActionType.Read;
|
||||
|
||||
constructor(public payload: number) {}
|
||||
}
|
||||
|
||||
export class ReadSuccess implements Action {
|
||||
readonly type = ActionType.ReadSuccess;
|
||||
|
||||
constructor(public payload: ProbeHost) {}
|
||||
}
|
||||
|
||||
export class ReadFailure implements Action {
|
||||
readonly type = ActionType.ReadFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export class Modify implements Action {
|
||||
readonly type = ActionType.Modify;
|
||||
|
||||
constructor(public payload: Probe) {}
|
||||
}
|
||||
|
||||
export class ModifySuccess implements Action {
|
||||
readonly type = ActionType.ModifySuccess;
|
||||
|
||||
constructor(public payload: ProbeHost) {}
|
||||
}
|
||||
|
||||
export class ModifyFailure implements Action {
|
||||
readonly type = ActionType.ModifyFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| ReadAllByDomainID
|
||||
| ReadAllByDomainIDSuccess
|
||||
| ReadAllByDomainIDFailure
|
||||
| Read
|
||||
| ReadSuccess
|
||||
| ReadFailure
|
||||
| Modify
|
||||
| ModifySuccess
|
||||
| ModifyFailure
|
||||
;
|
||||
@@ -1,81 +0,0 @@
|
||||
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 { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
import {
|
||||
ReadAllByDomainID,
|
||||
ReadAllByDomainIDFailure,
|
||||
ReadAllByDomainIDSuccess,
|
||||
Read,
|
||||
ReadSuccess,
|
||||
ReadFailure,
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ActionType
|
||||
} from './probe.action';
|
||||
import { ProbeHostService } from '../../../service/probe-host.service';
|
||||
import { ProbeService } from '../../../service/probe.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private probeHostService: ProbeHostService,
|
||||
private probeService: ProbeService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
ReadAllByDomainID$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ReadAllByDomainID)
|
||||
.map((action: ReadAllByDomainID) => action.payload)
|
||||
.switchMap(payload => this.probeHostService.readAllByDomainID(payload))
|
||||
.map(probeHosts => {
|
||||
return new ReadAllByDomainIDSuccess(probeHosts);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadAllByDomainIDFailure(error));
|
||||
});
|
||||
|
||||
@Effect()
|
||||
Read$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Read)
|
||||
.map((action: Read) => action.payload)
|
||||
.switchMap(payload => this.probeHostService.read(payload))
|
||||
.map(probeHost => {
|
||||
return new ReadSuccess(probeHost);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadFailure(error));
|
||||
});
|
||||
|
||||
@Effect()
|
||||
Modify$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Modify)
|
||||
.map((action: Modify) => action.payload)
|
||||
.switchMap(payload => this.probeService.modify(payload))
|
||||
.map(probe => {
|
||||
return new ModifySuccess(probe);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ModifyFailure(error));
|
||||
});
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
ActionReducerMap,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../probe.constant';
|
||||
|
||||
import * as ProbeEntityStore from './entity/probe';
|
||||
import * as ProbeListContainerStore from './container/probe-list';
|
||||
import * as ProbeDetailContainerStore from './container/probe-detail';
|
||||
import * as ProbeSelectorContainerStore from './container/probe-selector';
|
||||
|
||||
export interface State {
|
||||
probe_list_container: ProbeListContainerStore.State;
|
||||
probe_detail_container: ProbeDetailContainerStore.State;
|
||||
probe_selector_container: ProbeSelectorContainerStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
probe_list_container: ProbeListContainerStore.reducer,
|
||||
probe_detail_container: ProbeDetailContainerStore.reducer,
|
||||
probe_selector_container: ProbeSelectorContainerStore.reducer
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ProbeEntityStore.Effects,
|
||||
];
|
||||
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ProbeListContainerSelector = ProbeListContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_list_container
|
||||
));
|
||||
|
||||
export const ProbeDetailContainerSelector = ProbeDetailContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_detail_container
|
||||
));
|
||||
|
||||
export const ProbeSelectorContainerSelector = ProbeSelectorContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_selector_container
|
||||
));
|
||||
Reference in New Issue
Block a user