PATH:
home
/
letacommog
/
ldqm1
/
wp-content
/
plugins
/
woocommerce
/
packages
/
woocommerce-blocks
/
assets
/
js
/
hocs
/** * External dependencies */ import { useRef } from '@wordpress/element'; import { getSetting } from '@woocommerce/settings'; import { CART_STORE_KEY } from '@woocommerce/block-data'; import { useSelect } from '@wordpress/data'; /** * Hydrate Cart API data. * * Makes cart data available without an API request to wc/store/cart/. */ const useStoreCartApiHydration = () => { const cartData = useRef( getSetting( 'cartData' ) ); useSelect( ( select, registry ) => { if ( ! cartData.current ) { return; } const { isResolving, hasFinishedResolution } = select( CART_STORE_KEY ); const { receiveCart, receiveError, startResolution, finishResolution, } = registry.dispatch( CART_STORE_KEY ); if ( ! isResolving( 'getCartData', [] ) && ! hasFinishedResolution( 'getCartData', [] ) ) { startResolution( 'getCartData', [] ); if ( cartData.current?.code?.includes( 'error' ) ) { receiveError( cartData.current ); } else { receiveCart( cartData.current ); } finishResolution( 'getCartData', [] ); } }, [] ); }; /** * HOC that calls the useStoreCartApiHydration hook. * * @param {Function} OriginalComponent Component being wrapped. */ const withStoreCartApiHydration = ( OriginalComponent ) => { return ( props ) => { useStoreCartApiHydration(); return <OriginalComponent { ...props } />; }; }; export default withStoreCartApiHydration;
[+]
..
[-] index.js
[edit]
[-] with-categories.js
[edit]
[-] with-store-cart-api-hydration.js
[edit]
[-] with-searched-products.js
[edit]
[-] with-product-variations.js
[edit]
[-] with-category.js
[edit]
[+]
test
[-] with-transform-single-select-to-multiple-select.js
[edit]
[-] with-attributes.js
[edit]
[-] with-product.js
[edit]
[-] with-rest-api-hydration.js
[edit]