* Remove UPDATE_LEGACY_CART_FRAGMENTS

* bot: update checkstyle.xml

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Mike Jolley 2022-11-10 11:41:00 +00:00 committed by GitHub
parent 7eeabeea69
commit 25b4e18df2
6 changed files with 33 additions and 69 deletions

View File

@ -6,7 +6,6 @@ import { useCallback, useState, useEffect } from '@wordpress/element';
import { CART_STORE_KEY, CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
import { useDebounce } from 'use-debounce';
import { usePrevious } from '@woocommerce/base-hooks';
import { triggerFragmentRefresh } from '@woocommerce/base-utils';
import {
CartItem,
StoreCartItemQuantity,
@ -86,10 +85,7 @@ export const useStoreCartItemQuantity = (
const removeItem = useCallback( () => {
return cartItemKey
? removeItemFromCart( cartItemKey ).then( () => {
triggerFragmentRefresh();
return true;
} )
? removeItemFromCart( cartItemKey )
: Promise.resolve( false );
}, [ cartItemKey, removeItemFromCart ] );

View File

@ -42,23 +42,6 @@ export const dispatchEvent = (
element.dispatchEvent( event );
};
let fragmentRequestTimeoutId: ReturnType< typeof setTimeout >;
// This is a hack to trigger cart updates till we migrate to block based cart
// that relies on the store, see
// https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/1247
export const triggerFragmentRefresh = (): void => {
if ( fragmentRequestTimeoutId ) {
clearTimeout( fragmentRequestTimeoutId );
}
fragmentRequestTimeoutId = setTimeout( () => {
dispatchEvent( 'wc_fragment_refresh', {
bubbles: true,
cancelable: true,
} );
}, 50 );
};
export const triggerAddingToCartEvent = (): void => {
dispatchEvent( 'wc-blocks_adding_to_cart', {
bubbles: true,

View File

@ -12,7 +12,6 @@ export const ACTION_TYPES = {
SET_BILLING_ADDRESS: 'SET_BILLING_ADDRESS',
SET_SHIPPING_ADDRESS: 'SET_SHIPPING_ADDRESS',
UPDATING_SELECTED_SHIPPING_RATE: 'UPDATING_SELECTED_SHIPPING_RATE',
UPDATE_LEGACY_CART_FRAGMENTS: 'UPDATE_LEGACY_CART_FRAGMENTS',
TRIGGER_ADDING_TO_CART_EVENT: 'TRIGGER_ADDING_TO_CART_EVENT',
TRIGGER_ADDED_TO_CART_EVENT: 'TRIGGER_ADDED_TO_CART_EVENT',
} as const;

View File

@ -184,14 +184,6 @@ export const shippingRatesBeingSelected = ( isResolving: boolean ) =>
isResolving,
} as const );
/**
* Returns an action object for updating legacy cart fragments.
*/
export const updateCartFragments = () =>
( {
type: types.UPDATE_LEGACY_CART_FRAGMENTS,
} as const );
/**
* Triggers an adding to cart event so other blocks can update accordingly.
*/
@ -227,7 +219,6 @@ export function* applyExtensionCartUpdate(
cache: 'no-store',
} );
yield receiveCart( response );
yield updateCartFragments();
return response;
} catch ( error ) {
yield receiveError( error );
@ -265,7 +256,6 @@ export function* applyCoupon(
yield receiveCart( response );
yield receiveApplyingCoupon( '' );
yield updateCartFragments();
} catch ( error ) {
yield receiveError( error );
yield receiveApplyingCoupon( '' );
@ -306,7 +296,6 @@ export function* removeCoupon(
yield receiveCart( response );
yield receiveRemovingCoupon( '' );
yield updateCartFragments();
} catch ( error ) {
yield receiveError( error );
yield receiveRemovingCoupon( '' );
@ -351,7 +340,6 @@ export function* addItemToCart(
yield receiveCart( response );
yield triggerAddedToCartEvent( { preserveCartData: true } );
yield updateCartFragments();
} catch ( error ) {
yield receiveError( error );
@ -390,7 +378,6 @@ export function* removeItemFromCart(
} );
yield receiveCart( response );
yield updateCartFragments();
} catch ( error ) {
yield receiveError( error );
@ -437,7 +424,6 @@ export function* changeCartItemQuantity(
} );
yield receiveCart( response );
yield updateCartFragments();
} catch ( error ) {
yield receiveError( error );
@ -559,5 +545,4 @@ export type CartAction = ReturnOrGeneratorYieldUnion<
| typeof removeItemFromCart
| typeof changeCartItemQuantity
| typeof addItemToCart
| typeof updateCartFragments
>;

View File

@ -2,7 +2,6 @@
* External dependencies
*/
import {
triggerFragmentRefresh,
triggerAddedToCartEvent,
triggerAddingToCartEvent,
} from '@woocommerce/base-utils';
@ -13,9 +12,6 @@ import {
* @return {Object} An object with the controls to register with the store on the controls property of the registration object.
*/
export const controls = {
UPDATE_LEGACY_CART_FRAGMENTS() {
triggerFragmentRefresh();
},
TRIGGER_ADDING_TO_CART_EVENT() {
triggerAddingToCartEvent();
},

View File

@ -497,30 +497,30 @@
</file>
<file name="assets/js/data/cart/actions.ts">
<error line="14" column="10" severity="error" message="Module &apos;&quot;@wordpress/data&quot;&apos; has no exported member &apos;controls&apos;." source="TS2305" />
<error line="233" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="235" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="236" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="270" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="274" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="275" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="311" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="315" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="316" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="356" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="359" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="360" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="395" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="398" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="399" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="442" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="445" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="446" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="477" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="481" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="482" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="528" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="532" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="533" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="224" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="226" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="227" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="260" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="264" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="265" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="300" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="304" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="305" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="344" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="347" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="348" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="382" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="385" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="386" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="428" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="431" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="432" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="463" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="467" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="468" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="514" column="23" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;ResponseError | null | undefined&apos;." source="TS2345" />
<error line="518" column="8" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
<error line="519" column="23" severity="error" message="Object is of type &apos;unknown&apos;." source="TS2571" />
</file>
<file name="assets/js/data/cart/resolvers.ts">
<error line="5" column="10" severity="error" message="Module &apos;&quot;@wordpress/data&quot;&apos; has no exported member &apos;controls&apos;." source="TS2305" />
@ -633,7 +633,7 @@
<error line="30" column="42" severity="error" message="Property &apos;type&apos; does not exist on type &apos;Object&apos;." source="TS2339" />
</file>
<file name="assets/js/data/cart/controls.js">
<error line="22" column="31" severity="error" message="Parameter &apos;preserveCartData&apos; implicitly has an &apos;any&apos; type." source="TS7006" />
<error line="18" column="31" severity="error" message="Parameter &apos;preserveCartData&apos; implicitly has an &apos;any&apos; type." source="TS7006" />
</file>
<file name="assets/js/utils/notices.ts">
<error line="12" column="52" severity="error" message="Property &apos;type&apos; does not exist on type &apos;Notice&apos;." source="TS2339" />
@ -834,6 +834,12 @@
<error line="118" column="14" severity="error" message="Parameter &apos;error&apos; implicitly has an &apos;any&apos; type." source="TS7006" />
<error line="124" column="5" severity="error" message="Cannot find name &apos;receiveApplyingCoupon&apos;." source="TS2304" />
</file>
<file name="assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts">
<error line="149" column="3" severity="error" message="Type &apos;() =&gt; Promise&lt;boolean&gt; | Promise&lt;void&gt;&apos; is not assignable to type &apos;() =&gt; Promise&lt;boolean&gt;&apos;.
Type &apos;Promise&lt;boolean&gt; | Promise&lt;void&gt;&apos; is not assignable to type &apos;Promise&lt;boolean&gt;&apos;.
Type &apos;Promise&lt;void&gt;&apos; is not assignable to type &apos;Promise&lt;boolean&gt;&apos;.
Type &apos;void&apos; is not assignable to type &apos;boolean&apos;." source="TS2322" />
</file>
<file name="assets/js/base/context/hooks/use-query-state.js">
<error line="28" column="13" severity="error" message="Generic type &apos;Array&lt;T&gt;&apos; requires 1 type argument(s)." source="TS2314" />
<error line="131" column="5" severity="error" message="Argument of type &apos;Object | undefined&apos; is not assignable to parameter of type &apos;any[] | ComparableObject&apos;.
@ -882,8 +888,7 @@
</file>
<file name="assets/js/base/context/hooks/use-store-add-to-cart.ts">
<error line="93" column="3" severity="error" message="Type &apos;(quantity?: number) =&gt; Promise&lt;void&gt;&apos; is not assignable to type &apos;(quantity?: number | undefined) =&gt; Promise&lt;boolean&gt;&apos;.
Type &apos;Promise&lt;void&gt;&apos; is not assignable to type &apos;Promise&lt;boolean&gt;&apos;.
Type &apos;void&apos; is not assignable to type &apos;boolean&apos;." source="TS2322" />
Type &apos;Promise&lt;void&gt;&apos; is not assignable to type &apos;Promise&lt;boolean&gt;&apos;." source="TS2322" />
</file>
<file name="assets/js/base/context/providers/add-to-cart-form/form-state/actions.js">
<error line="42" column="27" severity="error" message="Parameter &apos;data&apos; implicitly has an &apos;any&apos; type." source="TS7006" />