getMarketplaceEntities selector: full Redux store state as param

This commit is contained in:
Kimmo Puputti 2017-05-02 12:46:18 +03:00
parent d42957de2a
commit 1f25e63d60
4 changed files with 7 additions and 14 deletions

View file

@ -193,7 +193,6 @@ InboxPageComponent.propTypes = {
};
const mapStateToProps = state => {
const marketplaceData = state.marketplaceData;
const {
fetchInProgress,
fetchOrdersOrSalesError,
@ -206,7 +205,7 @@ const mapStateToProps = state => {
fetchInProgress,
fetchOrdersOrSalesError,
pagination,
transactions: getMarketplaceEntities(marketplaceData, transactionRefs),
transactions: getMarketplaceEntities(state, transactionRefs),
currentUserHasListings,
currentUserHasListingsError,
};

View file

@ -67,10 +67,7 @@ const mapStateToProps = state => {
const { showListingError: showOrderError } = state.ListingPage;
const { currentUser } = state.user;
const transactions = getMarketplaceEntities(
state.marketplaceData,
transactionRef ? [transactionRef] : []
);
const transactions = getMarketplaceEntities(state, transactionRef ? [transactionRef] : []);
const transaction = transactions.length > 0 ? transactions[0] : null;
return { transaction, showOrderError, currentUser };

View file

@ -85,10 +85,7 @@ const mapStateToProps = state => {
const { showListingError: showSaleError } = state.ListingPage;
const { currentUser } = state.user;
const transactions = getMarketplaceEntities(
state.marketplaceData,
transactionRef ? [transactionRef] : []
);
const transactions = getMarketplaceEntities(state, transactionRef ? [transactionRef] : []);
const transaction = transactions.length > 0 ? transactions[0] : null;
return { transaction, showSaleError, currentUser };

View file

@ -49,8 +49,7 @@ export const getListingsById = (state, listingIds) => {
/**
* Get the denormalised entities from the given entity references.
*
* @param {Object} marketplaceData the state part of the Redux store
* for this reducer
* @param {Object} state the full Redux store
*
* @param {Array<{ id, type }} entityRefs References to entities that
* we want to query from the data. Currently we expect that all the
@ -58,11 +57,12 @@ export const getListingsById = (state, listingIds) => {
*
* @return {Array<Object>} denormalised entities
*/
export const getMarketplaceEntities = (marketplaceData, entityRefs) => {
export const getMarketplaceEntities = (state, entityRefs) => {
const { entities } = state.marketplaceData;
const type = entityRefs.length > 0 ? entityRefs[0].type : null;
const ids = entityRefs.map(ref => ref.id);
try {
return denormalisedEntities(marketplaceData.entities, type, ids);
return denormalisedEntities(entities, type, ids);
} catch (e) {
return [];
}