diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-03-20 16:02:22 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-03-20 16:02:22 +0100 |
commit | 3cb7c15d15f33e9b0ce06dbf0072021f6921dbe7 (patch) | |
tree | 4c828a5cb0c2d48f9dc3ec20de20a1ec025ca133 /src/client/react | |
parent | 32c7951d5e5db2dfde5305707e4d9bf021952db2 (diff) |
Rewrite users.js without using redux
Diffstat (limited to 'src/client/react')
-rw-r--r-- | src/client/react/users.js | 65 |
1 files changed, 9 insertions, 56 deletions
diff --git a/src/client/react/users.js b/src/client/react/users.js index 5bdf12f..492bf60 100644 --- a/src/client/react/users.js +++ b/src/client/react/users.js @@ -20,68 +20,21 @@ /* global USERS */ -import { combineReducers, createStore } from 'redux'; +import keyBy from 'lodash/keyBy'; const getId = ({ type, value }) => `${type}/${value}`; -const byId = (state = {}, action) => { - switch (action.type) { - case 'USERS/ADD_USER': - return { - ...state, - [action.user.id]: { - ...action.user, - }, - }; - default: - return state; - } -}; +const users = {}; -const allIds = (state = [], action) => { - switch (action.type) { - case 'USERS/ADD_USER': - return [ - ...state, - action.user.id, - ]; - default: - return state; - } -}; - -const allUsers = (state = [], action) => { - switch (action.type) { - case 'USERS/ADD_USER': - return [ - ...state, - { - ...action.user, - }, - ]; - default: - return state; - } -}; - -const store = createStore(combineReducers({ - byId, - allIds, - allUsers, +users.allUsers = USERS.map(user => ({ + type: user.type, + value: user.value, + alt: user.alt, + id: getId(user), })); -USERS.forEach((user) => { - store.dispatch({ - type: 'USERS/ADD_USER', - user: { - type: user.type, - value: user.value, - alt: user.alt, - id: getId(user), - }, - }); -}); +users.allIds = users.allUsers.map(user => user.id); -const users = store.getState(); +users.byId = keyBy(users.allUsers, 'id'); export default users; |