lunch/js/reducers/GroupReducer.js
2017-01-10 08:46:34 -05:00

25 lines
601 B
JavaScript

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;
}
};