ing
This commit is contained in:
30
@overflow/meta/crawler-input-item/store/index.ts
Normal file
30
@overflow/meta/crawler-input-item/store/index.ts
Normal 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
|
||||
));
|
||||
4
@overflow/meta/crawler-input-item/store/list/index.ts
Normal file
4
@overflow/meta/crawler-input-item/store/list/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './list.action';
|
||||
export * from './list.effect';
|
||||
export * from './list.reducer';
|
||||
export * from './list.state';
|
||||
37
@overflow/meta/crawler-input-item/store/list/list.action.ts
Normal file
37
@overflow/meta/crawler-input-item/store/list/list.action.ts
Normal 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
|
||||
|
||||
;
|
||||
@@ -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();
|
||||
}));
|
||||
});
|
||||
51
@overflow/meta/crawler-input-item/store/list/list.effect.ts
Normal file
51
@overflow/meta/crawler-input-item/store/list/list.effect.ts
Normal 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));
|
||||
});
|
||||
|
||||
}
|
||||
43
@overflow/meta/crawler-input-item/store/list/list.reducer.ts
Normal file
43
@overflow/meta/crawler-input-item/store/list/list.reducer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
@overflow/meta/crawler-input-item/store/list/list.state.ts
Normal file
15
@overflow/meta/crawler-input-item/store/list/list.state.ts
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user