var assign = require('object-assign'); var GroupConstants = require('../constants/GroupConstants'); module.exports = function(state = {}, action) { switch (action.type) { case GroupConstants.GROUPS_FETCHED: var groups = {}; for (var i = 0; i < action.groups.length; i++) { var group = action.groups[i]; groups[group.GroupId] = group; } return groups; case GroupConstants.GROUP_CREATED: case GroupConstants.GROUP_UPDATED: var group = action.group; var groups = assign({}, state, { [group.GroupId]: group }); return groups; default: return state; } };