mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
38 lines
1 KiB
JavaScript
38 lines
1 KiB
JavaScript
|
/**
|
||
|
* Resolvers: Handle asynchronous data fetching for the store.
|
||
|
*
|
||
|
* These functions update store state with data from external sources.
|
||
|
* Each resolver corresponds to a specific selector (selector with same name must exist).
|
||
|
* Resolvers are called automatically when selectors request unavailable data.
|
||
|
*
|
||
|
* @file
|
||
|
*/
|
||
|
|
||
|
import { dispatch } from '@wordpress/data';
|
||
|
import { __ } from '@wordpress/i18n';
|
||
|
import { apiFetch } from '@wordpress/data-controls';
|
||
|
|
||
|
import { STORE_NAME, REST_HYDRATE_PATH } from './constants';
|
||
|
|
||
|
export const resolvers = {
|
||
|
/**
|
||
|
* Retrieve settings from the site's REST API.
|
||
|
*/
|
||
|
*persistentData() {
|
||
|
try {
|
||
|
const result = yield apiFetch( { path: REST_HYDRATE_PATH } );
|
||
|
|
||
|
yield dispatch( STORE_NAME ).hydrate( result );
|
||
|
yield dispatch( STORE_NAME ).setIsReady( true );
|
||
|
} catch ( e ) {
|
||
|
yield dispatch( 'core/notices' ).createErrorNotice(
|
||
|
// TODO: Add the module name to the error message.
|
||
|
__(
|
||
|
'Error retrieving <UNKNOWN> details.',
|
||
|
'woocommerce-paypal-payments'
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
},
|
||
|
};
|