Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/data-controls/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ export function select( storeKey, selectorName, ...args ) {
};
}

/**
* Dispatches a control action for triggering a registry select.
*
* Note: This functions like the `select` control, but does not wait
* for resolvers.
*
* @param {string} storeKey The key for the store the selector belongs to.
* @param {string} selectorName The name of the selector.
* @param {Array} args Arguments for the select.
*
* @example
* ```js
* import { __unstableSyncSelect } from '@wordpress/data-controls';
*
* // Action generator using `__unstableSyncSelect`.
* export function* myAction() {
* const isEditorSideBarOpened = yield __unstableSyncSelect( 'core/edit-post', 'isEditorSideBarOpened' );
* // Do stuff with the result from the `__unstableSyncSelect`.
* }
* ```
*
* @return {Object} The control descriptor.
*/
export function __unstableSyncSelect( storeKey, selectorName, ...args ) {
return {
type: 'SYNC_SELECT',
storeKey,
selectorName,
args,
};
}

/**
* Dispatches a control action for triggering a registry dispatch.
*
Expand Down Expand Up @@ -133,6 +165,11 @@ export const controls = {
]( storeKey )[ selectorName ]( ...args );
}
),
SYNC_SELECT: createRegistryControl(
( registry ) => ( { storeKey, selectorName, args } ) => {
return registry.select( storeKey )[ selectorName ]( ...args );
}
),
DISPATCH: createRegistryControl(
( registry ) => ( { storeKey, actionName, args } ) => {
return registry.dispatch( storeKey )[ actionName ]( ...args );
Expand Down
9 changes: 7 additions & 2 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { has, castArray } from 'lodash';
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { dispatch, select, apiFetch } from '@wordpress/data-controls';
import {
dispatch,
select,
__unstableSyncSelect,
apiFetch,
} from '@wordpress/data-controls';
import { parse, synchronizeBlocksWithTemplate } from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -672,7 +677,7 @@ export function* resetEditorBlocks( blocks, options = {} ) {
if ( __unstableShouldCreateUndoLevel !== false ) {
const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
const noChange =
( yield select(
( yield __unstableSyncSelect(
'core',
'getEditedEntityRecord',
'postType',
Expand Down