Server IP : 104.21.14.103 / Your IP : 13.59.139.220 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/hocs/ |
Upload File : |
/** * External dependencies */ import { useRef } from '@wordpress/element'; import { getSetting } from '@woocommerce/settings'; import { SCHEMA_STORE_KEY } from '@woocommerce/block-data'; import { useSelect } from '@wordpress/data'; /** * Hydrate Rest API data from settings to reduce the number of API requests needed. */ const useRestApiHydration = () => { const restApiRoutes = useRef( getSetting( 'restApiRoutes' ) ); useSelect( ( select, registry ) => { if ( ! restApiRoutes.current ) { return; } const { isResolving, hasFinishedResolution } = select( SCHEMA_STORE_KEY ); const { receiveRoutes, startResolution, finishResolution, } = registry.dispatch( SCHEMA_STORE_KEY ); Object.keys( restApiRoutes.current ).forEach( ( namespace ) => { const routes = restApiRoutes.current[ namespace ]; if ( ! isResolving( 'getRoutes', [ namespace ] ) && ! hasFinishedResolution( 'getRoutes', [ namespace ] ) ) { startResolution( 'getRoutes', [ namespace ] ); receiveRoutes( routes, [ namespace ] ); finishResolution( 'getRoutes', [ namespace ] ); } } ); }, [] ); }; /** * HOC that calls the useRestApiHydration hook. * * @param {Function} OriginalComponent Component being wrapped. */ const withRestApiHydration = ( OriginalComponent ) => { return ( props ) => { useRestApiHydration(); return <OriginalComponent { ...props } />; }; }; export default withRestApiHydration;