diff options
author | cwm <chriswmartin@protonmail.com> | 2017-12-08 19:40:49 -0600 |
---|---|---|
committer | cwm <chriswmartin@protonmail.com> | 2017-12-08 19:40:49 -0600 |
commit | f44c8fd130e51b5d8f707be8fd53ccc81211eb73 (patch) | |
tree | ea0ab9a2504b3d7569e8ef820708f5cd7059f304 /app/javascript/flavours/glitch/reducers/lists.js | |
parent | 776867ea73f2fb9180a90b09cd98d801ca2aeef0 (diff) |
merged tootsuite pr #5750 into glitch flavour
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; + } +}; |