1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-26 15:42:27 -05:00

Stop creating lists in containers

Create them only when needed in reducers instead
This commit is contained in:
Aaron Lindsay 2017-06-21 21:27:05 -04:00
parent cd9ad1d4d7
commit 25b04a4f0f
5 changed files with 57 additions and 29 deletions

View File

@ -288,7 +288,7 @@ class ReportsTab extends React.Component {
</ButtonGroup>
<ButtonGroup>
<Combobox
data={this.props.report_list}
data={this.props.reports.list}
valueField='ReportId'
textField={item => typeof item === 'string' ? item : item.Name}
value={selectedReport}

View File

@ -8,16 +8,11 @@ var ImportActions = require('../actions/ImportActions');
var AccountsTab = require('../components/AccountsTab');
function mapStateToProps(state) {
var security_list = [];
for (var securityId in state.securities) {
if (state.securities.hasOwnProperty(securityId))
security_list.push(state.securities[securityId]);
}
return {
accounts: state.accounts.map,
accountChildren: state.accounts.children,
securities: state.securities,
security_list: security_list,
securities: state.securities.map,
security_list: state.securities.list,
selectedAccount: state.selectedAccount,
transactions: state.transactions,
transactionPage: state.transactionPage,

View File

@ -4,14 +4,8 @@ var ReportActions = require('../actions/ReportActions');
var ReportsTab = require('../components/ReportsTab');
function mapStateToProps(state) {
var report_list = [];
for (var reportId in state.reports.map) {
if (state.reports.map.hasOwnProperty(reportId))
report_list.push(state.reports.map[reportId]);
}
return {
reports: state.reports,
report_list: report_list
reports: state.reports
}
}

View File

@ -11,14 +11,9 @@ function mapStateToProps(state) {
&& state.accounts.map[accountId].SecurityId == state.selectedSecurity)
selectedSecurityAccounts.push(state.accounts.map[accountId]);
}
var security_list = [];
for (var securityId in state.securities) {
if (state.securities.hasOwnProperty(securityId))
security_list.push(state.securities[securityId]);
}
return {
securities: state.securities,
security_list: security_list,
securities: state.securities.map,
security_list: state.securities.list,
selectedSecurityAccounts: selectedSecurityAccounts,
selectedSecurity: state.selectedSecurity,
securityTemplates: state.securityTemplates

View File

@ -3,27 +3,71 @@ var assign = require('object-assign');
var SecurityConstants = require('../constants/SecurityConstants');
var UserConstants = require('../constants/UserConstants');
module.exports = function(state = {}, action) {
var SecurityType = require('../models').SecurityType;
const initialState = {
map: {},
list: [],
currency_list: []
}
function mapToList(securities) {
var security_list = [];
for (var securityId in securities) {
if (securities.hasOwnProperty(securityId))
security_list.push(securities[securityId]);
}
return security_list;
}
function mapToCurrencyList(securities) {
var security_list = [];
for (var securityId in securities) {
if (securities.hasOwnProperty(securityId) && securities[securityId].Type == SecurityType.Currency)
security_list.push(securities[securityId]);
}
return security_list;
}
module.exports = function(state = initialState, action) {
switch (action.type) {
case SecurityConstants.SECURITIES_FETCHED:
var securities = {};
var list = [];
var currency_list = [];
for (var i = 0; i < action.securities.length; i++) {
var security = action.securities[i];
securities[security.SecurityId] = security;
list.push(security);
if (security.Type == SecurityType.Currency)
currency_list.push(security);
}
return securities;
return {
map: securities,
list: list,
currency_list: currency_list
};
case SecurityConstants.SECURITY_CREATED:
case SecurityConstants.SECURITY_UPDATED:
var security = action.security;
return assign({}, state, {
var map = assign({}, state.map, {
[security.SecurityId]: security
});
return {
map: map,
list: mapToList(map),
currency_list: mapToCurrencyList(map)
};
case SecurityConstants.SECURITY_REMOVED:
var newstate = assign({}, state);
delete newstate[action.securityId];
return newstate;
var map = assign({}, state.map);
delete map[action.securityId];
return {
map: map,
list: mapToList(map),
currency_list: mapToCurrencyList(map)
};
case UserConstants.USER_LOGGEDOUT:
return {};
return initialState;
default:
return state;
}