|
1 | 1 | define([ |
2 | 2 | 'redux', |
3 | | - '../actions/collaborationsActions', |
| 3 | + '../actions/collaborationsActions' |
4 | 4 | ], (redux, ACTION_NAMES) => { |
5 | 5 | let initialState = { |
6 | 6 | listCollaborationsPending: false, |
7 | 7 | listCollaborationsSuccessful: false, |
8 | 8 | listCollaborationsError: null, |
9 | | - collaborations: [], |
| 9 | + list: [], |
10 | 10 | } |
11 | 11 |
|
12 | | - return (state = initialState, action) => { |
13 | | - switch (action.type) { |
14 | | - case ACTION_NAMES.LIST_COLLABORATIONS_START: |
15 | | - return { |
16 | | - ...state, |
17 | | - listCollaborationsPending: true, |
18 | | - listCollaborationsSuccessful: false, |
19 | | - listCollaborationsError: null |
20 | | - }; |
21 | | - |
22 | | - case ACTION_NAMES.LIST_COLLABORATIONS_SUCCESSFUL: |
23 | | - return { |
24 | | - ...state, |
25 | | - listCollaborationsPending: false, |
26 | | - listCollaborationsSuccessful: true, |
27 | | - collaborations: action.payload |
28 | | - }; |
29 | | - |
30 | | - case ACTION_NAMES.LIST_COLLABORATIONS_FAILED: |
31 | | - return { |
32 | | - ...state, |
33 | | - listCollaborationsPending: false, |
34 | | - listCollaborationsError: action.payload |
35 | | - }; |
36 | | - |
37 | | - default: |
38 | | - return state; |
| 12 | + let collaborationsHandlers = { |
| 13 | + [ACTION_NAMES.LIST_COLLABORATIONS_START]: (state, action) => { |
| 14 | + return { |
| 15 | + ...state, |
| 16 | + listCollaborationsPending: true, |
| 17 | + listCollaborationsSuccessful: false, |
| 18 | + listCollaborationsError: null |
| 19 | + }; |
| 20 | + }, |
| 21 | + [ACTION_NAMES.LIST_COLLABORATIONS_SUCCESSFUL]: (state, action) => { |
| 22 | + return { |
| 23 | + ...state, |
| 24 | + listCollaborationsPending: false, |
| 25 | + listCollaborationsSuccessful: true, |
| 26 | + list: action.payload |
| 27 | + } |
| 28 | + }, |
| 29 | + [ACTION_NAMES.LIST_COLLABORATIONS_FAILED]: (state, action) => { |
| 30 | + return { |
| 31 | + ...state, |
| 32 | + listCollaborationsPending: false, |
| 33 | + listCollaborationsError: action.payload |
| 34 | + } |
39 | 35 | } |
40 | 36 | }; |
| 37 | + |
| 38 | + return (state = initialState, action) => { |
| 39 | + if (collaborationsHandlers[action.type]) { |
| 40 | + return collaborationsHandlers[action.type](state, action) |
| 41 | + } else { |
| 42 | + return state |
| 43 | + } |
| 44 | + } |
41 | 45 | }) |
0 commit comments