Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Change updateCartFromApi to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed May 31, 2021
1 parent 2566106 commit d0f49cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Expand Up @@ -3,17 +3,22 @@
*/
import { CART_STORE_KEY } from '@woocommerce/block-data';
import { select, dispatch } from '@wordpress/data';
import type { CartResponse } from '@woocommerce/type-defs/cart-response';

/**
* When executed, this will invalidate the getCartData selector, causing a request to be made
* to the API. This is in place to allow extensions to signal that they have modified the cart,
* and that it needs to be reloaded in the client.
*/
export const updateCartFromApi = () => {
export const updateCartFromApi = (): void => {
const { getCartData } = select( CART_STORE_KEY );
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Can't figure out why invalidateResolutionForStoreSelector isn't available
// but it's a standard action dispatched by @wordpress/data.
const { invalidateResolutionForStoreSelector, receiveCart } = dispatch(
CART_STORE_KEY
);
invalidateResolutionForStoreSelector( 'getCartData' );
receiveCart( getCartData() );
const cartData = ( getCartData() as unknown ) as CartResponse;
receiveCart( cartData );
};
3 changes: 2 additions & 1 deletion packages/tsconfig.json
Expand Up @@ -10,7 +10,8 @@
"../assets/js/base/hooks",
"../settings/shared/index.ts",
"../settings/blocks/index.ts",
"../type-defs"
"../type-defs",
"../assets/js/data"
],
"exclude": [ "**/test/**" ]
}

0 comments on commit d0f49cc

Please sign in to comment.