Browse Source

reduce setState to one call in walletsData compWillMount

all-modes
pbca26 8 years ago
parent
commit
8343a30cee
  1. 27
      react/src/components/dashboard/walletsData/walletsData.js

27
react/src/components/dashboard/walletsData/walletsData.js

@ -249,15 +249,16 @@ class WalletsData extends React.Component {
componentWillReceiveProps(props) { componentWillReceiveProps(props) {
let historyToSplit; let historyToSplit;
let stateObj = {};
if (this.props && if (this.props &&
this.props.ActiveCoin && this.props.ActiveCoin &&
this.props.ActiveCoin.coin) { this.props.ActiveCoin.coin) {
if (!this.state.currentAddress && if (!this.state.currentAddress &&
this.props.ActiveCoin.activeAddress) { this.props.ActiveCoin.activeAddress) {
this.setState(Object.assign({}, this.state, { stateObj = Object.assign(stateObj, {
currentAddress: this.props.ActiveCoin.activeAddress, currentAddress: this.props.ActiveCoin.activeAddress,
})); });
} }
if (this.props.ActiveCoin.txhistory && if (this.props.ActiveCoin.txhistory &&
@ -273,22 +274,22 @@ class WalletsData extends React.Component {
this.state.activePage * this.state.itemsPerPage this.state.activePage * this.state.itemsPerPage
); );
this.setState(Object.assign({}, this.state, { stateObj = Object.assign(stateObj, {
itemsList: historyToSplit, itemsList: historyToSplit,
})); });
} }
} }
if (!historyToSplit && if (!historyToSplit &&
this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory &&
this.props.ActiveCoin.txhistory === 'no data') { this.props.ActiveCoin.txhistory === 'no data') {
this.setState(Object.assign({}, this.state, { stateObj = Object.assign(stateObj, {
itemsList: 'no data', itemsList: 'no data',
})); });
} else if (!historyToSplit && this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'loading') { } else if (!historyToSplit && this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'loading') {
this.setState(Object.assign({}, this.state, { stateObj = Object.assign(stateObj, {
itemsList: 'loading', itemsList: 'loading',
})); });
} else if ( // dirty first txhistory load workaround } else if ( // dirty first txhistory load workaround
!historyToSplit && !historyToSplit &&
this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory &&
@ -302,11 +303,13 @@ class WalletsData extends React.Component {
this.state.activePage * this.state.itemsPerPage this.state.activePage * this.state.itemsPerPage
); );
this.setState(Object.assign({}, this.state, { stateObj = Object.assign(stateObj, {
itemsList: historyToSplit, itemsList: historyToSplit,
})); });
} }
} }
this.setState(Object.assign({}, this.state, stateObj));
} }
updateCurrentPage(page) { updateCurrentPage(page) {

Loading…
Cancel
Save