1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-10-30 07:40:05 -04:00
moneygo/js/reducers/AccountReducer.js

28 lines
757 B
JavaScript
Raw Normal View History

2016-10-03 19:49:15 -04:00
var assign = require('object-assign');
var AccountConstants = require('../constants/AccountConstants');
module.exports = function(state = {}, action) {
switch (action.type) {
case AccountConstants.ACCOUNTS_FETCHED:
var accounts = {};
for (var i = 0; i < action.accounts.length; i++) {
var account = action.accounts[i];
accounts[account.AccountId] = account;
}
return accounts;
case AccountConstants.ACCOUNT_CREATED:
case AccountConstants.ACCOUNT_UPDATED:
var account = action.account;
return assign({}, state, {
[account.AccountId]: account
});
case AccountConstants.ACCOUNT_REMOVED:
var newstate = assign({}, state);
delete newstate[action.accountId];
return newstate;
default:
return state;
}
};