How to use the @wordpress/data-controls.select 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* resetEditorBlocks( blocks, options = {} ) {
	const {
		__unstableShouldCreateUndoLevel,
		selectionStart,
		selectionEnd,
	} = options;
	const edits = { blocks, selectionStart, selectionEnd };

	if ( __unstableShouldCreateUndoLevel !== false ) {
		const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
		const noChange =
			( yield select( 'core', 'getEditedEntityRecord', 'postType', type, id ) )
				.blocks === edits.blocks;
		if ( noChange ) {
			return yield dispatch(
				'core',
				'__unstableCreateUndoLevel',
				'postType',
				type,
				id
			);
		}

		// We create a new function here on every persistent edit
		// to make sure the edit makes the post dirty and creates
		// a new undo level.
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
export function* refreshPost() {
	const post = yield select(
		STORE_KEY,
		'getCurrentPost'
	);
	const postTypeSlug = yield select(
		STORE_KEY,
		'getCurrentPostType'
	);
	const postType = yield select(
		'core',
		'getPostType',
		postTypeSlug
	);
	const newPost = yield apiFetch(
		{
			// Timestamp arg allows caller to bypass browser caching, which is
			// expected for this specific function.
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
);
	if ( error ) {
		const args = getNotificationArgumentsForSaveFail( {
			post: previousRecord,
			edits,
			error,
		} );
		if ( args.length ) {
			yield dispatch( 'core/notices', 'createErrorNotice', ...args );
		}
	} else {
		const updatedRecord = yield select( STORE_KEY, 'getCurrentPost' );
		const args = getNotificationArgumentsForSaveSuccess( {
			previousPost: previousRecord,
			post: updatedRecord,
			postType: yield select( 'core', 'getPostType', updatedRecord.type ),
			options,
		} );
		if ( args.length ) {
			yield dispatch( 'core/notices', 'createSuccessNotice', ...args );
		}
		// Make sure that any edits after saving create an undo level and are
		// considered for change detection.
		if ( ! options.isAutosave ) {
			yield dispatch( 'core/block-editor', '__unstableMarkLastChangeAsPersistent' );
		}
	}
}
github php4dev / heroku-wordpress / wp-content / plugins / woocommerce / packages / woocommerce-blocks / assets / js / data / collections / resolvers.js View on Github external
export function* getCollection( namespace, resourceName, query, ids ) {
	const route = yield select(
		SCHEMA_STORE_KEY,
		'getRoute',
		namespace,
		resourceName,
		ids
	);
	const queryString = addQueryArgs( '', query );
	if ( ! route ) {
		yield receiveCollection( namespace, resourceName, queryString, ids );
		return;
	}

	try {
		const {
			response = DEFAULT_EMPTY_ARRAY,
			headers,
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
export function* savePost( options = {} ) {
	if ( ! ( yield select( STORE_KEY, 'isEditedPostSaveable' ) ) ) {
		return;
	}
	let edits = {
		content: yield select( STORE_KEY, 'getEditedPostContent' ),
	};
	if ( ! options.isAutosave ) {
		yield dispatch( STORE_KEY, 'editPost', edits, { undoIgnore: true } );
	}

	yield __experimentalRequestPostUpdateStart( options );
	const previousRecord = yield select( STORE_KEY, 'getCurrentPost' );
	edits = {
		id: previousRecord.id,
		...( yield select(
			'core',
			'getEntityRecordNonTransientEdits',
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,
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
export function* savePost( options = {} ) {
	if ( ! ( yield select( STORE_KEY, 'isEditedPostSaveable' ) ) ) {
		return;
	}
	let edits = {
		content: yield select( STORE_KEY, 'getEditedPostContent' ),
	};
	if ( ! options.isAutosave ) {
		yield dispatch( STORE_KEY, 'editPost', edits, { undoIgnore: true } );
	}

	yield __experimentalRequestPostUpdateStart( options );
	const previousRecord = yield select( STORE_KEY, 'getCurrentPost' );
	edits = {
		id: previousRecord.id,
		...( yield select(
			'core',
			'getEntityRecordNonTransientEdits',
			'postType',
			previousRecord.type,
			previousRecord.id
		) ),
github php4dev / heroku-wordpress / wp-content / plugins / woo-gutenberg-products-block / assets / js / data / collections / actions.js View on Github external
export function* __experimentalPersistItemToCollection(
	namespace,
	resourceName,
	currentCollection,
	data = {}
) {
	const newCollection = [ ...currentCollection ];
	const route = yield select(
		SCHEMA_STORE_KEY,
		'getRoute',
		namespace,
		resourceName
	);
	if ( ! route ) {
		return;
	}

	try {
		const item = yield apiFetch( {
			path: route,
			method: 'POST',
			data,
			cache: 'no-store',
		} );
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 );
	}
}

@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