Skip to content

Instantly share code, notes, and snippets.

@delianides
Created April 12, 2016 18:24
Show Gist options
  • Save delianides/729a35e455cad1f650180c10530fe4d3 to your computer and use it in GitHub Desktop.
Save delianides/729a35e455cad1f650180c10530fe4d3 to your computer and use it in GitHub Desktop.
// XXX How do I include GiveState here?
import { assign } from "lodash";
const addTransaction = (state: any, action: any): any => {
let total = 0;
let mergedTransactions = assign(state.transactions, action.transactions);
for (let fund in mergedTransactions) {
if (typeof mergedTransactions[fund].value != "number") {
delete mergedTransactions[fund];
}
total = total + mergedTransactions[fund].value;
}
return assign(state, { transactions: mergedTransactions, total: total });
}
const clearTransaction = (state: any, action: any): any => {
let total = 0;
// console.log(action.transactionId, state.transactions)
if (!action.transactionId || !state.transactions[action.transactionId]) {
return state;
}
delete state.transactions[action.transactionId];
for (let fund in state.transactions) {
if (typeof state.transactions[fund].value != "number") {
delete state.transactions[fund];
}
total = total + state.transactions[fund].value;
}
return assign(state, { transactions: state.transactions, total: total });
}
const clearTransactions = (state: any): any => {
return assign(state, { total: 0, transactions: {} });
}
export default {
addTransaction: addTransaction,
clearTransaction: clearTransaction,
clearTransactions: clearTransactions
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment