-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathboard.reducer.ts
46 lines (40 loc) · 1.82 KB
/
board.reducer.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
42
43
44
45
46
import * as BoardActions from './board.actions';
import { BoardModel } from './board.model';
import { Board } from './board';
export type Action = BoardActions.All;
const initialState = {
pending: false,
boards : [],
board : {}
};
const newState = (state, newData ) => Object.assign({}, state, newData);
export function boardReducer(state = initialState, action : Action){
// console.log(action);
switch(action.type){
case BoardActions.GET_BOARDS :
return newState(state, { pending: true });
case BoardActions.GET_BOARD :
return newState(state, { pending: true });
case BoardActions.ADD_BOARD :
return newState(state, { pending: true } );
case BoardActions.EDIT_BOARD :
return newState(state, { pending: true } );
case BoardActions.DELETE_BOARD :
return newState(state, { pending: true } );
case BoardActions.GET_BOARDS_SUCCESS :
return newState(state, { pending: false, boards : action.boards });
case BoardActions.GET_BOARD_SUCCESS :
return newState(state, { pending: false, board : action.board });
case BoardActions.ADD_BOARD_SUCCESS :
state.boards.push(action.board);
return newState(state, { pending: false, boards : state.boards } );
case BoardActions.EDIT_BOARD_SUCCESS :
state.pending = false;
state.boards.filter(v => v.id === action.id).map( (e, index) => Object.keys(e).map(v => e[v] = action.board[v]) );
return newState(state, { pending: false, boards : state.boards });
case BoardActions.DELETE_BOARD_SUCCESS :
state.pending = false;
return newState(state, { boards : state.boards.filter(v => v.id !== action.id) } );
default : state;
}
}