How to use the @wordpress/data-controls.dispatch function in @wordpress/data-controls

To help you get started, we’ve selected a few @wordpress/data-controls 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 / packages / editor / src / store / actions.js View on Github external
export function* editPost( edits, options ) {
	const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
	yield dispatch(
		'core',
		'editEntityRecord',
		'postType',
		type,
		id,
		edits,
		options
	);
}
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
const getBlockEditorAction = ( name ) => function* ( ...args ) {
	deprecated( '`wp.data.dispatch( \'core/editor\' ).' + name + '`', {
		alternative: '`wp.data.dispatch( \'core/block-editor\' ).' + name + '`',
	} );
	yield dispatch( 'core/block-editor', name, ...args );
};
github WordPress / gutenberg / packages / edit-widgets / src / store / actions.js View on Github external
export function* saveWidgetAreas() {
	const widgetAreas = yield select(
		'core/edit-widgets',
		'getWidgetAreas',
	);
	for ( const { id } of widgetAreas ) {
		const blocks = yield select(
			'core/edit-widgets',
			'getBlocksFromWidgetArea',
			id
		);
		yield dispatch(
			'core',
			'saveWidgetArea',
			{
				id,
				content: serialize( blocks ),
			}
		);
	}

	yield dispatch(
		'core/notices',
		'createSuccessNotice',
		__( 'Block areas saved succesfully.' ),
		{
			id: WIDGET_AREAS_SAVE_NOTICE_ID,
			type: 'snackbar',
github php4dev / heroku-wordpress / wp-content / plugins / woocommerce / packages / woocommerce-blocks / assets / js / data / collections / resolvers.js View on Github external
function* invalidateModifiedCollection( timestamp ) {
	const lastModified = yield select( STORE_KEY, 'getCollectionLastModified' );

	if ( ! lastModified ) {
		yield dispatch( STORE_KEY, 'receiveLastModified', timestamp );
	} else if ( timestamp > lastModified ) {
		yield dispatch( STORE_KEY, 'invalidateResolutionForStore' );
		yield dispatch( STORE_KEY, 'receiveLastModified', timestamp );
	}
}
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
export function* resetAutosave( newAutosave ) {
	deprecated( 'resetAutosave action (`core/editor` store)', {
		alternative: 'receiveAutosaves action (`core` store)',
		plugin: 'Gutenberg',
	} );

	const postId = yield select( STORE_KEY, 'getCurrentPostId' );
	yield dispatch( 'core', 'receiveAutosaves', postId, newAutosave );

	return { type: '__INERT__' };
}
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
'removeNotice',
		TRASH_POST_NOTICE_ID
	);
	try {
		const post = yield select(
			STORE_KEY,
			'getCurrentPost'
		);
		yield apiFetch(
			{
				path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
				method: 'DELETE',
			}
		);

		yield dispatch(
			STORE_KEY,
			'savePost'
		);
	} catch ( error ) {
		yield dispatch(
			'core/notices',
			'createErrorNotice',
			...getNotificationArgumentsForTrashFail( { error } ),
		);
	}
}
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
}

	yield __experimentalRequestPostUpdateStart( options );
	const previousRecord = yield select( STORE_KEY, 'getCurrentPost' );
	edits = {
		id: previousRecord.id,
		...( yield select(
			'core',
			'getEntityRecordNonTransientEdits',
			'postType',
			previousRecord.type,
			previousRecord.id
		) ),
		...edits,
	};
	yield dispatch(
		'core',
		'saveEntityRecord',
		'postType',
		previousRecord.type,
		edits,
		options
	);
	yield __experimentalRequestPostUpdateFinish( options );

	const error = yield select(
		'core',
		'getLastEntitySaveError',
		'postType',
		previousRecord.type,
		previousRecord.id
	);
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
export function* trashPost() {
	const postTypeSlug = yield select(
		STORE_KEY,
		'getCurrentPostType'
	);
	const postType = yield select(
		'core',
		'getPostType',
		postTypeSlug
	);
	yield dispatch(
		'core/notices',
		'removeNotice',
		TRASH_POST_NOTICE_ID
	);
	try {
		const post = yield select(
			STORE_KEY,
			'getCurrentPost'
		);
		yield apiFetch(
			{
				path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
				method: 'DELETE',
			}
		);
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
export function* redo() {
	yield dispatch( 'core', 'redo' );
}

@wordpress/data-controls

A set of common controls for the @wordpress/data api.

GPL-2.0-or-later
Latest version published 3 days ago

Package Health Score

95 / 100
Full package analysis