UNPKG

@shopgate/engage

Version:
13 lines 1.16 kB
import{createSelector}from'reselect';import{getProductId,getProductState}from'@shopgate/pwa-common-commerce/product/selectors/product';/** * Retrieves the product media state. * @param {Object} state The application state. * @returns {Object} The product options state. */export var getProductMediaState=createSelector(getProductState,function(state){return state.mediaByProductId;});/** * Creates a selector that retrieves product media for a passed product id. * @returns {Function} */export var makeGetProductMedia=function makeGetProductMedia(){return(/** * Retrieves the current products media. * @param {Object} state The application state. * @param {Object} props The component props. * @returns {Object[]|null} The product media collection. */createSelector(getProductId,function(state,props){return props.types;},getProductMediaState,function(productId,types,productMediaState){var productMedia=productMediaState[productId];if(!productMedia||productMedia.isFetching){return null;}if(!types||!productMedia.media){return productMedia.media;}return productMedia.media.filter(function(media){return types.includes(media.type);});}));};