-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathboard.effects.ts
41 lines (31 loc) · 1.52 KB
/
board.effects.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Actions, Effect } from '@ngrx/effects';
import { Observable } from 'rxjs';
import * as BoardActions from './board.actions';
import { BoardService } from './board.service';
export type Action = BoardActions.All;
@Injectable()
export class BoardEffects {
constructor(private actions$ : Actions, private boardService : BoardService){}
@Effect() getBoards$ = this.actions$
.ofType(BoardActions.GET_BOARDS)
.switchMap((action : any) => this.boardService.getBoards())
.map(v => new BoardActions.GetBoardsSuccess(v));
@Effect() getBoard$ = this.actions$
.ofType(BoardActions.GET_BOARD)
.switchMap((action : any) => this.boardService.getBoard(action.id))
.map(v => new BoardActions.GetBoardSuccess(v));
@Effect() addBoard$ = this.actions$
.ofType(BoardActions.ADD_BOARD)
.switchMap((action : any) => this.boardService.addBoard(action.board))
.map(v => new BoardActions.AddBoardSuccess(v));
@Effect() editBoard$ = this.actions$
.ofType(BoardActions.EDIT_BOARD)
.switchMap((action : any) => this.boardService.editBoard(action.id, action.board))
.map( (v : any) => new BoardActions.EditBoardSuccess(v.id, { ...v }));
@Effect() deleteBoard$ = this.actions$
.ofType(BoardActions.DELETE_BOARD)
.switchMap((action : any) => this.boardService.deleteBoard(action.id))
.map( (v : any) => new BoardActions.DeleteBoardSuccess(v));
}