CoinList: memoize coinList for performance
This commit is contained in:
parent
e7d360baae
commit
8961fc1b68
|
@ -4,19 +4,33 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import CryptoAddress from './crypto_address';
|
import CryptoAddress from './crypto_address';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const makeGetCoinList = () => {
|
||||||
// Address example:
|
return createSelector(
|
||||||
// {"ticker": "btc", "address": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n", "note": "This is our main address"}
|
[(addresses, limit) => typeof limit === 'number' ? addresses.take(limit) : addresses],
|
||||||
const addresses = state.getIn(['soapbox', 'cryptoAddresses']);
|
addresses => addresses,
|
||||||
const { limit } = ownProps;
|
);
|
||||||
|
|
||||||
return {
|
|
||||||
coinList: typeof limit === 'number' ? addresses.take(limit) : addresses,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
const makeMapStateToProps = () => {
|
||||||
|
const getCoinList = makeGetCoinList();
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => {
|
||||||
|
// Address example:
|
||||||
|
// {"ticker": "btc", "address": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n", "note": "This is our main address"}
|
||||||
|
const addresses = state.getIn(['soapbox', 'cryptoAddresses']);
|
||||||
|
const { limit } = ownProps;
|
||||||
|
|
||||||
|
return {
|
||||||
|
coinList: getCoinList(addresses, limit),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return mapStateToProps;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default @connect(makeMapStateToProps)
|
||||||
class CoinList extends ImmutablePureComponent {
|
class CoinList extends ImmutablePureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
|
Loading…
Reference in New Issue