Remove setSettings. (https://github.com/woocommerce/woocommerce-blocks/pull/3607)
* Remove setSettings. * No deprecated warrning from setSettings so we should not expect it.
This commit is contained in:
parent
0e971bb16a
commit
ed612e6e09
|
@ -9,7 +9,6 @@ import compareVersions from 'compare-versions';
|
||||||
import { getSetting } from './get-setting';
|
import { getSetting } from './get-setting';
|
||||||
|
|
||||||
export * from './default-constants';
|
export * from './default-constants';
|
||||||
export { setSetting } from './set-setting';
|
|
||||||
import '../../filters/exclude-draft-status-from-analytics';
|
import '../../filters/exclude-draft-status-from-analytics';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 );
|
|
||||||
}
|
|
|
@ -1,10 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { isWpVersion, setSetting } from '..';
|
import { isWpVersion } from '..';
|
||||||
|
import { allSettings } from '../settings-init';
|
||||||
|
|
||||||
describe( 'isWpVersion', () => {
|
describe( 'isWpVersion', () => {
|
||||||
let initial = true;
|
|
||||||
it.each`
|
it.each`
|
||||||
version | operator | result
|
version | operator | result
|
||||||
${ '5.3-beta1' } | ${ '<' } | ${ true }
|
${ '5.3-beta1' } | ${ '<' } | ${ true }
|
||||||
|
@ -18,13 +18,8 @@ describe( 'isWpVersion', () => {
|
||||||
'should return $result when $version is the current wpVersion ' +
|
'should return $result when $version is the current wpVersion ' +
|
||||||
'and `5.3` is the version compared using `$operator`',
|
'and `5.3` is the version compared using `$operator`',
|
||||||
( { version, operator, result } ) => {
|
( { version, operator, result } ) => {
|
||||||
setSetting( 'wpVersion', version );
|
// eslint-disable-next-line
|
||||||
// deprecated caches messages once per session, so we only check
|
allSettings[ 'wpVersion' ] = version;
|
||||||
// console warn on initial call.
|
|
||||||
if ( initial ) {
|
|
||||||
expect( console ).toHaveWarned();
|
|
||||||
}
|
|
||||||
initial = false;
|
|
||||||
expect( isWpVersion( '5.3', operator ) ).toBe( result );
|
expect( isWpVersion( '5.3', operator ) ).toBe( result );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -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 );
|
|
||||||
} );
|
|
||||||
} );
|
|
Loading…
Reference in New Issue