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,4 @@
export * from './modify.action';
export * from './modify.effect';
export * from './modify.reducer';
export * from './modify.state';

View File

@@ -0,0 +1,34 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { Target } from '@overflow/commons-typescript/model/target';
export enum ActionType {
Modify = '[Target.modify] Modify',
ModifySuccess = '[Target.modify] ModifySuccess',
ModifyFailure = '[Target.modify] ModifyFailure',
}
export class Modify implements Action {
readonly type = ActionType.Modify;
constructor(public payload: Target) {}
}
export class ModifySuccess implements Action {
readonly type = ActionType.ModifySuccess;
constructor(public payload: Target) {}
}
export class ModifyFailure implements Action {
readonly type = ActionType.ModifyFailure;
constructor(public payload: RPCClientError) {}
}
export type Actions =
| Modify
| ModifySuccess
| ModifyFailure
;

View File

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

View File

@@ -0,0 +1,44 @@
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/map';
import 'rxjs/add/operator/take';
import { TargetService } from '../../service/target.service';
import {
Modify,
ModifySuccess,
ModifyFailure,
ActionType,
} from './modify.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private targetService: TargetService,
private router: Router
) { }
@Effect()
modify$: Observable<Action> = this.actions$
.ofType(ActionType.Modify)
.map((action: Modify) => action.payload)
.exhaustMap(target =>
this.targetService.modify(target)
.map(targets => new ModifySuccess(targets))
.catch(error => of(new ModifyFailure(error)))
);
}

View File

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

View File

@@ -0,0 +1,14 @@
import { RPCClientError } from '@loafer/ng-rpc';
import { Target } from '@overflow/commons-typescript/model/target';
export interface State {
error: RPCClientError | null;
pending: boolean;
target: Target | null;
}
export const initialState: State = {
error: null,
pending: false,
target: null,
};