This commit is contained in:
crusader
2018-06-01 19:27:27 +09:00
parent f290f5bdb1
commit fd369d3519
75 changed files with 77 additions and 1718 deletions

View File

@@ -1,19 +0,0 @@
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import {
REDUCERS,
EFFECTS,
} from './store';
import { MODULE } from './sensor-item.constant';
@NgModule({
imports: [
StoreModule.forFeature(MODULE.name, REDUCERS),
EffectsModule.forFeature(EFFECTS),
],
})
export class SensorItemStoreModule { }

View File

@@ -4,14 +4,12 @@ import { CommonModule } from '@angular/common';
import { UIModule } from '@overflow/shared/ui/ui.module';
import { COMPONENTS } from './component';
import { SensorItemStoreModule } from './sensor-item-store.module';
import { SERVICES } from './service';
@NgModule({
imports: [
CommonModule,
UIModule,
SensorItemStoreModule,
],
declarations: [
COMPONENTS,

View File

@@ -1,29 +0,0 @@
import {
createSelector,
createFeatureSelector,
} from '@ngrx/store';
import { StateSelector } from '@overflow/core/ngrx/store';
import * as ListStore from './key-list';
import { MODULE } from '../sensor-item.constant';
export interface State {
list: ListStore.State;
}
export const REDUCERS = {
list: ListStore.reducer,
};
export const EFFECTS = [
ListStore.Effects,
];
export const selectState = createFeatureSelector<State>(MODULE.name);
export const ReadSensorItemKeySelector = new StateSelector<ListStore.State>(createSelector(
selectState,
(state: State) => state.list
));

View File

@@ -1,4 +0,0 @@
export * from './list.action';
export * from './list.effect';
export * from './list.reducer';
export * from './list.state';

View File

@@ -1,37 +0,0 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { MetaSensorItemKey } from '@overflow/commons-typescript/model/meta';
import { MetaSensorDisplayItem } from '@overflow/commons-typescript/model/meta';
export enum ActionType {
ReadAllByDisplayItem = '[meta.sensor-display-key-list] ReadAllByDisplayItem',
ReadAllByDisplayItemSuccess = '[meta.sensor-display-key-list] ReadAllByDisplayItemSuccess',
ReadAllByDisplayItemFailure = '[meta.sensor-display-key-list] ReadAllByDisplayItemFailure',
}
export class ReadAllByDisplayItem implements Action {
readonly type = ActionType.ReadAllByDisplayItem;
constructor(public payload: MetaSensorDisplayItem) {}
}
export class ReadAllByDisplayItemSuccess implements Action {
readonly type = ActionType.ReadAllByDisplayItemSuccess;
constructor(public payload: MetaSensorItemKey[]) {}
}
export class ReadAllByDisplayItemFailure implements Action {
readonly type = ActionType.ReadAllByDisplayItemFailure;
constructor(public payload: RPCClientError) {}
}
export type Actions =
| ReadAllByDisplayItem
| ReadAllByDisplayItemSuccess
| ReadAllByDisplayItemFailure
;

View File

@@ -1,15 +0,0 @@
import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './list.effect';
describe('List.Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Effects]
});
});
it('should be created', inject([Effects], (effects: Effects) => {
expect(effects).toBeTruthy();
}));
});

View File

@@ -1,48 +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 {
ReadAllByDisplayItem,
ReadAllByDisplayItemSuccess,
ReadAllByDisplayItemFailure,
ActionType,
} from './list.action';
import { SensorItemDependencyService } from '../../service/sensor-item-dependency.service';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private service: SensorItemDependencyService,
private router: Router
) { }
@Effect()
readAllByDisplayItem$: Observable<Action> = this.actions$
.ofType(ActionType.ReadAllByDisplayItem)
.map((action: ReadAllByDisplayItem) => action.payload)
.switchMap(payload => this.service.readAllByDisplayItem(payload))
.map(list => {
return new ReadAllByDisplayItemSuccess(list);
})
.catch((error: RPCClientError) => {
return of(new ReadAllByDisplayItemFailure(error));
});
}

View File

@@ -1,43 +0,0 @@
import {
Actions,
ActionType,
} from './list.action';
import {
State,
initialState,
} from './list.state';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.ReadAllByDisplayItem: {
return {
...state,
error: null,
pending: true,
};
}
case ActionType.ReadAllByDisplayItemSuccess: {
return {
...state,
error: null,
pending: false,
list: action.payload
};
}
case ActionType.ReadAllByDisplayItemFailure: {
return {
...state,
error: action.payload,
pending: false,
list: null,
};
}
default: {
return state;
}
}
}

View File

@@ -1,15 +0,0 @@
import { RPCClientError } from '@loafer/ng-rpc';
import { MetaSensorItemKey } from '@overflow/commons-typescript/model/meta';
export interface State {
error: RPCClientError | null;
pending: boolean;
list: MetaSensorItemKey[] | null;
}
export const initialState: State = {
error: null,
pending: false,
list: null,
};