This commit is contained in:
crusader
2018-05-24 15:44:13 +09:00
parent b69539d368
commit d59d9379f9
514 changed files with 4868 additions and 8262 deletions

View File

@@ -0,0 +1,30 @@
import {
createSelector,
createFeatureSelector,
ActionReducerMap,
} from '@ngrx/store';
import { StateSelector } from '@overflow/core/ngrx/store';
import * as ListStore from './list';
import { MODULE } from '../crawler-input.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 ReadCrawlerInputItemSelector = new StateSelector<ListStore.State>(createSelector(
selectState,
(state: State) => state.list
));

View File

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

View File

@@ -0,0 +1,37 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
import { MetaCrawlerInputItem } from '@overflow/commons-typescript/model/meta';
export enum ActionType {
ReadAll = '[meta.crawler-input-list] ReadAll',
ReadAllSuccess = '[meta.crawler-input-list] ReadAllSuccess',
ReadAllFailure = '[meta.crawler-input-list] ReadAllFailure',
}
export class ReadAll implements Action {
readonly type = ActionType.ReadAll;
constructor(public payload: MetaCrawler) {}
}
export class ReadAllSuccess implements Action {
readonly type = ActionType.ReadAllSuccess;
constructor(public payload: MetaCrawlerInputItem[]) {}
}
export class ReadAllFailure implements Action {
readonly type = ActionType.ReadAllFailure;
constructor(public payload: RPCClientError) {}
}
export type Actions =
| ReadAll
| ReadAllSuccess
| ReadAllFailure
;

View File

@@ -0,0 +1,15 @@
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

@@ -0,0 +1,51 @@
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 { DomainMember } from '@overflow/commons-typescript/model/domain';
import {
ReadAll,
ReadAllSuccess,
ReadAllFailure,
ActionType,
} from './list.action';
import { MetaCrawlerInputItemService } from '../../service/crawler-input-item.service';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private service: MetaCrawlerInputItemService,
private router: Router
) { }
@Effect()
readAll$: Observable<Action> = this.actions$
.ofType(ActionType.ReadAll)
.map((action: ReadAll) => action.payload)
.switchMap(payload => this.service.readAllByMetaCrawler(payload))
.map(list => {
return new ReadAllSuccess(list);
})
.catch((error: RPCClientError) => {
return of(new ReadAllFailure(error));
});
}

View File

@@ -0,0 +1,43 @@
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.ReadAll: {
return {
...state,
error: null,
pending: true,
};
}
case ActionType.ReadAllSuccess: {
return {
...state,
error: null,
pending: false,
inputs: action.payload
};
}
case ActionType.ReadAllFailure: {
return {
...state,
error: action.payload,
pending: false,
inputs: null,
};
}
default: {
return state;
}
}
}

View File

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