How to use the @wordpress/data.restrictPersistence function in @wordpress/data

To help you get started, we’ve selected a few @wordpress/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / editor / store / index.js View on Github external
* Internal dependencies
 */
import reducer from './reducer';
import applyMiddlewares from './middlewares';
import * as selectors from './selectors';
import * as actions from './actions';
import * as tokens from '../components/rich-text/core-tokens';
import { validateTokenSettings } from '../components/rich-text/tokens';

/**
 * Module Constants
 */
const MODULE_KEY = 'core/editor';

const store = registerStore( MODULE_KEY, {
	reducer: restrictPersistence( reducer, 'preferences' ),
	selectors,
	actions,
	persist: true,
} );
applyMiddlewares( store );

forOwn( tokens, ( { name, settings } ) => {
	settings = validateTokenSettings( name, settings, store.getState() );

	if ( settings ) {
		store.dispatch( actions.registerToken( name, settings ) );
	}
} );

export default store;