1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-29 00:22:28 -05:00
moneygo/js/reducers/SecurityReducer.js

31 lines
898 B
JavaScript
Raw Normal View History

2016-10-05 13:36:47 -04:00
var assign = require('object-assign');
var SecurityConstants = require('../constants/SecurityConstants');
var UserConstants = require('../constants/UserConstants');
module.exports = function(state = {}, action) {
switch (action.type) {
case SecurityConstants.SECURITIES_FETCHED:
var securities = {};
for (var i = 0; i < action.securities.length; i++) {
var security = action.securities[i];
securities[security.SecurityId] = security;
}
return securities;
case SecurityConstants.SECURITY_CREATED:
case SecurityConstants.SECURITY_UPDATED:
var security = action.security;
return assign({}, state, {
[security.SecurityId]: security
});
case SecurityConstants.SECURITY_REMOVED:
var newstate = assign({}, state);
delete newstate[action.securityId];
return newstate;
case UserConstants.USER_LOGGEDOUT:
return {};
default:
return state;
}
};