How to use the @wordpress/data.plugins.persistence 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 Automattic / wp-calypso / apps / full-site-editing / full-site-editing-plugin / wpcom-block-editor-nux / src / store.js View on Github external
/* eslint-disable import/no-extraneous-dependencies */
/**
 * External dependencies
 */
import apiFetch from '@wordpress/api-fetch';
import { plugins, registerStore, use } from '@wordpress/data';

use( plugins.persistence, {} );

const reducer = ( state = {}, { type, isNuxEnabled } ) =>
	'WPCOM_BLOCK_EDITOR_NUX_SET_STATUS' === type ? { ...state, isNuxEnabled } : state;

const actions = {
	setWpcomNuxStatus: ( { isNuxEnabled, bypassApi } ) => {
		if ( ! bypassApi ) {
			apiFetch( {
				path: 'fse/v1/wpcom-block-editor/nux',
				method: 'POST',
				data: { isNuxEnabled },
			} );
		}
		return {
			type: 'WPCOM_BLOCK_EDITOR_NUX_SET_STATUS',
			isNuxEnabled,
github Automattic / wp-calypso / client / gutenberg / editor / init.js View on Github external
export const initGutenberg = once( ( userId, store ) => {
	debug( 'Starting Gutenberg editor initialization...' );

	const registry = use( addResetToRegistry );

	debug( 'Registering data plugins' );
	const storageKey = 'WP_DATA_USER_' + userId;
	use( plugins.persistence, { storageKey: storageKey } );
	use( plugins.controls );

	debug( 'Initializing gutenberg/calypso store' );
	require( 'gutenberg/editor/calypso-store' );

	// We need to ensure that core-data is loaded after the data plugins have been registered.
	debug( 'Initializing core-data store' );
	require( '@wordpress/core-data' );

	// Avoid using top level imports for this since they will statically
	// initialize core-data before required plugins are loaded.
	const { registerCoreBlocks } = require( '@wordpress/block-library' );
	const { unregisterBlockType, setFreeformContentHandlerName } = require( '@wordpress/blocks' );

	debug( 'Registering core blocks' );
	registerCoreBlocks();
github Automattic / wp-calypso / client / landing / gutenboarding / stores / onboard / index.ts View on Github external
import { controls } from '@wordpress/data-controls';
import { plugins, registerStore, use } from '@wordpress/data';

/**
 * Internal dependencies
 */
import { STORE_KEY } from './constants';
import reducer, { State } from './reducer';
import * as actions from './actions';
import * as selectors from './selectors';
import * as resolvers from './resolvers';
import { SelectFromMap, DispatchFromMap } from '../mapped-types';

export { STORE_KEY };

use( plugins.persistence, {} );

registerStore< State >( STORE_KEY, {
	actions,
	controls,
	reducer,
	resolvers,
	selectors,
	persist: [ 'domain', 'siteTitle', 'siteVertical' ],
} );

declare module '@wordpress/data' {
	function dispatch( key: typeof STORE_KEY ): DispatchFromMap< typeof actions >;
	function select( key: typeof STORE_KEY ): SelectFromMap< typeof selectors >;
}