1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-11-01 00:10:06 -04:00
moneygo/js/reducers/TransactionReducer.js

33 lines
997 B
JavaScript
Raw Normal View History

2017-05-24 19:47:18 -04:00
var assign = require('object-assign');
var TransactionConstants = require('../constants/TransactionConstants');
var UserConstants = require('../constants/UserConstants');
module.exports = function(state = {}, action) {
switch (action.type) {
case TransactionConstants.TRANSACTION_PAGE_FETCHED:
var transactions = assign({}, state);
for (var tidx in action.transactions) {
var t = action.transactions[tidx];
transactions = assign({}, transactions, {
[t.TransactionId]: t
});
}
return transactions;
case TransactionConstants.TRANSACTION_CREATED:
case TransactionConstants.TRANSACTION_UPDATED:
var transaction = action.transaction;
return assign({}, state, {
[transaction.TransactionId]: transaction
});
case TransactionConstants.TRANSACTION_REMOVED:
var transactions = assign({}, state);
delete transactions[action.transactionId];
return transactions;
case UserConstants.USER_LOGGEDOUT:
return {};
default:
return state;
}
};