diff options
author | cwm <chriswmartin@protonmail.com> | 2017-12-10 15:22:15 -0600 |
---|---|---|
committer | cwm <chriswmartin@protonmail.com> | 2017-12-10 15:22:15 -0600 |
commit | 072ab191cc47692bad1145a26aa27912aeefb12f (patch) | |
tree | d217dc63f36554c7271b1c68a90d8d044640a732 /app/javascript/flavours/glitch/reducers/lists.js | |
parent | eec5d350fdb94fa44c6938ca059166ff3e3e67b3 (diff) | |
parent | 26c9b9fa276fd629789fd06f65a5d698b182f67a (diff) |
pulled master, moved locale entry to new location
Diffstat (limited to 'app/javascript/flavours/glitch/reducers/lists.js')
-rw-r--r-- | app/javascript/flavours/glitch/reducers/lists.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/reducers/lists.js b/app/javascript/flavours/glitch/reducers/lists.js new file mode 100644 index 000000000..f30ffbcbd --- /dev/null +++ b/app/javascript/flavours/glitch/reducers/lists.js @@ -0,0 +1,37 @@ +import { + LIST_FETCH_SUCCESS, + LIST_FETCH_FAIL, + LISTS_FETCH_SUCCESS, + LIST_CREATE_SUCCESS, + LIST_UPDATE_SUCCESS, + LIST_DELETE_SUCCESS, +} from '../actions/lists'; +import { Map as ImmutableMap, fromJS } from 'immutable'; + +const initialState = ImmutableMap(); + +const normalizeList = (state, list) => state.set(list.id, fromJS(list)); + +const normalizeLists = (state, lists) => { + lists.forEach(list => { + state = normalizeList(state, list); + }); + + return state; +}; + +export default function lists(state = initialState, action) { + switch(action.type) { + case LIST_FETCH_SUCCESS: + case LIST_CREATE_SUCCESS: + case LIST_UPDATE_SUCCESS: + return normalizeList(state, action.list); + case LISTS_FETCH_SUCCESS: + return normalizeLists(state, action.lists); + case LIST_DELETE_SUCCESS: + case LIST_FETCH_FAIL: + return state.set(action.id, false); + default: + return state; + } +}; |