* Remove setSettings.

* No deprecated warrning from setSettings so we should not expect it.
This commit is contained in:
Bartosz Budzanowski 2021-01-05 14:09:07 +01:00 committed by GitHub
parent 0e971bb16a
commit ed612e6e09
4 changed files with 4 additions and 69 deletions

View File

@ -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';
/**

View File

@ -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 );
}

View File

@ -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 );
}
);

View File

@ -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 );
} );
} );