Skip to content

Commit

Permalink
My Jetpack: avoid performing a request for each product (#22605)
Browse files Browse the repository at this point in the history
* my-jetpack: remove getProduct() resolver

* changelog
  • Loading branch information
retrofox authored Feb 1, 2022
1 parent 0752934 commit b82e303
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
22 changes: 1 addition & 21 deletions projects/packages/my-jetpack/_inc/state/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,9 @@ import apiFetch from '@wordpress/api-fetch';
/**
* Internal dependencies
*/
import { REST_API_SITE_PURCHASES_ENDPOINT, REST_API_SITE_PRODUCTS_ENDPOINT } from './constants';
import { REST_API_SITE_PURCHASES_ENDPOINT } from './constants';

const myJetpackResolvers = {
getProduct: productId => async ( { dispatch } ) => {
dispatch.setIsFetchingProduct( productId, true );
try {
dispatch.setProduct(
await apiFetch( {
path: `${ REST_API_SITE_PRODUCTS_ENDPOINT }/${ productId }`,
} )
);
dispatch.setIsFetchingProduct( productId, false );
} catch ( error ) {
dispatch.setIsFetchingProduct( productId, false );

// Pick error from the response body.
if ( error?.code && error?.message ) {
dispatch.setRequestProductError( productId, error );
} else {
throw new Error( error );
}
}
},
getPurchases: () => async ( { dispatch } ) => {
dispatch.setPurchasesIsFetching( true );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Remove getProduct() resolver

0 comments on commit b82e303

Please sign in to comment.