lunch/js/reducers/SuggestionReducer.js

31 lines
938 B
JavaScript

var assign = require('object-assign');
var SuggestionConstants = require('../constants/SuggestionConstants');
var UserConstants = require('../constants/UserConstants');
module.exports = function(state = {}, action) {
switch (action.type) {
case SuggestionConstants.SUGGESTIONS_FETCHED:
var suggestions = {};
for (var i = 0; i < action.suggestions.length; i++) {
var suggestion = action.suggestions[i];
suggestions[suggestion.SuggestionId] = suggestion;
}
return suggestions;
case SuggestionConstants.SUGGESTION_CREATED:
var suggestion = action.suggestion;
var suggestions = assign({}, state, {
[suggestion.SuggestionId]: suggestion
});
return suggestions;
case SuggestionConstants.SUGGESTION_REMOVED:
var suggestions = assign({}, state);
delete suggestions[action.suggestionId];
return suggestions;
case UserConstants.USER_LOGGEDOUT:
return {};
default:
return state;
}
};