aboutsummaryrefslogtreecommitdiff
path: root/src/client/react
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react')
-rw-r--r--src/client/react/users.js65
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;