From db1989aefb5c4747de0dabbade2a9a4d29959f88 Mon Sep 17 00:00:00 2001 From: Thomas Roberts <5656702+opr@users.noreply.github.com> Date: Fri, 4 Mar 2022 14:42:16 +0000 Subject: [PATCH] Remove `fromEntriesPolyfill` (https://github.com/woocommerce/woocommerce-blocks/pull/5981) * Remove fromEntriesPolyfill * Remove further instances of fromEntriesPolyfill --- .../js/base/context/hooks/cart/use-store-cart.ts | 7 ++----- .../js/base/utils/derive-selected-shipping-rates.js | 7 +------ .../assets/js/base/utils/from-entries-polyfill.ts | 13 ------------- .../assets/js/base/utils/index.js | 1 - 4 files changed, 3 insertions(+), 25 deletions(-) delete mode 100644 plugins/woocommerce-blocks/assets/js/base/utils/from-entries-polyfill.ts diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts index 7430f0978bc..7df7c0db26e 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts @@ -28,10 +28,7 @@ import type { CartResponseCouponItem, CartResponseCoupons, } from '@woocommerce/types'; -import { - emptyHiddenAddressFields, - fromEntriesPolyfill, -} from '@woocommerce/base-utils'; +import { emptyHiddenAddressFields } from '@woocommerce/base-utils'; /** * Internal dependencies @@ -85,7 +82,7 @@ const defaultCartTotals: CartResponseTotals = { const decodeValues = ( object: Record< string, unknown > ): Record< string, unknown > => - fromEntriesPolyfill( + Object.fromEntries( Object.entries( object ).map( ( [ key, value ] ) => [ key, decodeEntities( value ), diff --git a/plugins/woocommerce-blocks/assets/js/base/utils/derive-selected-shipping-rates.js b/plugins/woocommerce-blocks/assets/js/base/utils/derive-selected-shipping-rates.js index 4c27031b40c..3e7c8a3219c 100644 --- a/plugins/woocommerce-blocks/assets/js/base/utils/derive-selected-shipping-rates.js +++ b/plugins/woocommerce-blocks/assets/js/base/utils/derive-selected-shipping-rates.js @@ -1,8 +1,3 @@ -/** - * Internal dependencies - */ -import { fromEntriesPolyfill } from './from-entries-polyfill'; - /** * Get an array of selected shipping rates keyed by Package ID. * @@ -10,7 +5,7 @@ import { fromEntriesPolyfill } from './from-entries-polyfill'; * @return {Object} Object containing the package IDs and selected rates in the format: { [packageId:string]: rateId:string } */ export const deriveSelectedShippingRates = ( shippingRates ) => - fromEntriesPolyfill( + Object.fromEntries( shippingRates.map( ( { package_id: packageId, shipping_rates: packageRates } ) => [ packageId, diff --git a/plugins/woocommerce-blocks/assets/js/base/utils/from-entries-polyfill.ts b/plugins/woocommerce-blocks/assets/js/base/utils/from-entries-polyfill.ts deleted file mode 100644 index 5d8590cc462..00000000000 --- a/plugins/woocommerce-blocks/assets/js/base/utils/from-entries-polyfill.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * A polyfill for Object.fromEntries function. - * - * @param {Array<[string, unknown]>} array Array to be turned back to object - * @return {Record< string, unknown >} the newly created object - */ -export const fromEntriesPolyfill = ( - array: Array< [ string, unknown ] > -): Record< string, unknown > => - array.reduce< Record< string, unknown > >( ( obj, [ key, val ] ) => { - obj[ key ] = val; - return obj; - }, {} ); diff --git a/plugins/woocommerce-blocks/assets/js/base/utils/index.js b/plugins/woocommerce-blocks/assets/js/base/utils/index.js index 1e611655a44..82fb3565a72 100644 --- a/plugins/woocommerce-blocks/assets/js/base/utils/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/utils/index.js @@ -6,5 +6,4 @@ export * from './render-frontend'; export * from './get-valid-block-attributes'; export * from './product-data'; export * from './derive-selected-shipping-rates'; -export * from './from-entries-polyfill'; export * from './get-icons-from-payment-methods';