From ed612e6e09e6ed2e6e00bedf3f3463389755c7d4 Mon Sep 17 00:00:00 2001 From: Bartosz Budzanowski Date: Tue, 5 Jan 2021 14:09:07 +0100 Subject: [PATCH] Remove setSettings. (https://github.com/woocommerce/woocommerce-blocks/pull/3607) * Remove setSettings. * No deprecated warrning from setSettings so we should not expect it. --- .../assets/js/settings/shared/index.js | 1 - .../assets/js/settings/shared/set-setting.js | 36 ------------------- .../shared/test/compare-with-wp-version.js | 13 +++---- .../js/settings/shared/test/set-setting.js | 23 ------------ 4 files changed, 4 insertions(+), 69 deletions(-) delete mode 100644 plugins/woocommerce-blocks/assets/js/settings/shared/set-setting.js delete mode 100644 plugins/woocommerce-blocks/assets/js/settings/shared/test/set-setting.js diff --git a/plugins/woocommerce-blocks/assets/js/settings/shared/index.js b/plugins/woocommerce-blocks/assets/js/settings/shared/index.js index 8fc5c578948..66ecd2a2e50 100644 --- a/plugins/woocommerce-blocks/assets/js/settings/shared/index.js +++ b/plugins/woocommerce-blocks/assets/js/settings/shared/index.js @@ -9,7 +9,6 @@ import compareVersions from 'compare-versions'; import { getSetting } from './get-setting'; export * from './default-constants'; -export { setSetting } from './set-setting'; import '../../filters/exclude-draft-status-from-analytics'; /** diff --git a/plugins/woocommerce-blocks/assets/js/settings/shared/set-setting.js b/plugins/woocommerce-blocks/assets/js/settings/shared/set-setting.js deleted file mode 100644 index 7260476aba1..00000000000 --- a/plugins/woocommerce-blocks/assets/js/settings/shared/set-setting.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * External dependencies - */ -import deprecated from '@wordpress/deprecated'; - -/** - * Internal dependencies - */ -import { allSettings } from './settings-init'; - -/** - * Sets a value to a property on the settings state. - * - * @param {string} name The setting property key for the - * setting being mutated. - * @param {*} value The value to set. - * @param {Function} [filter=( val ) => val] Allows for providing a callback - * to sanitize the setting (eg. - * ensure it's a number) - * - * @todo Remove setSetting function from `@woocommerce/settings`. - * - * The `wc.wcSettings.setSetting` function was deprecated beginning with WooCommerce Blocks 3.2.0 - * and can be removed completely with WooCommerce Blocks 3.8.0 (that gives 6 versions of the - * feature plugin for warning and 3 versions of WooCommerce core). - */ -export function setSetting( name, value, filter = ( val ) => val ) { - deprecated( 'setSetting', { - version: '3.8.0', - alternative: `a locally scoped value for "${ name }"`, - plugin: 'WooCommerce Blocks', - hint: - 'wc.wcSettings is a global settings configuration object that should not be mutated during a session. Hence the removal of this function.', - } ); - allSettings[ name ] = filter( value ); -} diff --git a/plugins/woocommerce-blocks/assets/js/settings/shared/test/compare-with-wp-version.js b/plugins/woocommerce-blocks/assets/js/settings/shared/test/compare-with-wp-version.js index a19cd5f8429..6b5d038bac0 100644 --- a/plugins/woocommerce-blocks/assets/js/settings/shared/test/compare-with-wp-version.js +++ b/plugins/woocommerce-blocks/assets/js/settings/shared/test/compare-with-wp-version.js @@ -1,10 +1,10 @@ /** * Internal dependencies */ -import { isWpVersion, setSetting } from '..'; +import { isWpVersion } from '..'; +import { allSettings } from '../settings-init'; describe( 'isWpVersion', () => { - let initial = true; it.each` version | operator | result ${ '5.3-beta1' } | ${ '<' } | ${ true } @@ -18,13 +18,8 @@ describe( 'isWpVersion', () => { 'should return $result when $version is the current wpVersion ' + 'and `5.3` is the version compared using `$operator`', ( { version, operator, result } ) => { - setSetting( 'wpVersion', version ); - // deprecated caches messages once per session, so we only check - // console warn on initial call. - if ( initial ) { - expect( console ).toHaveWarned(); - } - initial = false; + // eslint-disable-next-line + allSettings[ 'wpVersion' ] = version; expect( isWpVersion( '5.3', operator ) ).toBe( result ); } ); diff --git a/plugins/woocommerce-blocks/assets/js/settings/shared/test/set-setting.js b/plugins/woocommerce-blocks/assets/js/settings/shared/test/set-setting.js deleted file mode 100644 index 13072ea3896..00000000000 --- a/plugins/woocommerce-blocks/assets/js/settings/shared/test/set-setting.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Internal dependencies - */ -import { setSetting } from '../set-setting'; -import { getSetting } from '../get-setting'; - -describe( 'setSetting', () => { - it( 'should add a new value to the settings state for value not present', () => { - setSetting( 'aSetting', 42 ); - expect( console ).toHaveWarned(); - expect( getSetting( 'aSetting' ) ).toBe( 42 ); - } ); - it( 'should replace existing value', () => { - setSetting( 'adminUrl', 'not original' ); - expect( console ).toHaveWarned(); - expect( getSetting( 'adminUrl' ) ).toBe( 'not original' ); - } ); - it( 'should save the value run through the provided filter', () => { - setSetting( 'bSetting', 'who', () => 42 ); - expect( console ).toHaveWarned(); - expect( getSetting( 'aSetting' ) ).toBe( 42 ); - } ); -} );