Add coexistence checks to all enqueue methods to prevent loading both React and Grid.js assets simultaneously. Changes: - ReactAdmin.php: Only enqueue React assets when ?react=1 - Init.php: Skip Grid.js when React active on admin pages - Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0 - Customer.php, Product.php, License.php: Add coexistence checks Now the toggle between Classic and React versions works correctly. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
133 lines
4.1 KiB
JavaScript
133 lines
4.1 KiB
JavaScript
/**
|
|
* Internal dependencies
|
|
*/
|
|
import { createRegistryControl } from './factory';
|
|
|
|
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
|
|
const SELECT = '@@data/SELECT';
|
|
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
|
|
const DISPATCH = '@@data/DISPATCH';
|
|
function isObject(object) {
|
|
return object !== null && typeof object === 'object';
|
|
}
|
|
|
|
/**
|
|
* Dispatches a control action for triggering a synchronous registry select.
|
|
*
|
|
* Note: This control synchronously returns the current selector value, triggering the
|
|
* resolution, but not waiting for it.
|
|
*
|
|
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
* @param {string} selectorName The name of the selector.
|
|
* @param {Array} args Arguments for the selector.
|
|
*
|
|
* @example
|
|
* ```js
|
|
* import { controls } from '@wordpress/data';
|
|
*
|
|
* // Action generator using `select`.
|
|
* export function* myAction() {
|
|
* const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );
|
|
* // Do stuff with the result from the `select`.
|
|
* }
|
|
* ```
|
|
*
|
|
* @return {Object} The control descriptor.
|
|
*/
|
|
function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
return {
|
|
type: SELECT,
|
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
selectorName,
|
|
args
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Dispatches a control action for triggering and resolving a registry select.
|
|
*
|
|
* Note: when this control action is handled, it automatically considers
|
|
* selectors that may have a resolver. In such case, it will return a `Promise` that resolves
|
|
* after the selector finishes resolving, with the final result value.
|
|
*
|
|
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
* @param {string} selectorName The name of the selector
|
|
* @param {Array} args Arguments for the selector.
|
|
*
|
|
* @example
|
|
* ```js
|
|
* import { controls } from '@wordpress/data';
|
|
*
|
|
* // Action generator using resolveSelect
|
|
* export function* myAction() {
|
|
* const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );
|
|
* // do stuff with the result from the select.
|
|
* }
|
|
* ```
|
|
*
|
|
* @return {Object} The control descriptor.
|
|
*/
|
|
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
return {
|
|
type: RESOLVE_SELECT,
|
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
selectorName,
|
|
args
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Dispatches a control action for triggering a registry dispatch.
|
|
*
|
|
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
* @param {string} actionName The name of the action to dispatch
|
|
* @param {Array} args Arguments for the dispatch action.
|
|
*
|
|
* @example
|
|
* ```js
|
|
* import { controls } from '@wordpress/data-controls';
|
|
*
|
|
* // Action generator using dispatch
|
|
* export function* myAction() {
|
|
* yield controls.dispatch( 'core/editor', 'togglePublishSidebar' );
|
|
* // do some other things.
|
|
* }
|
|
* ```
|
|
*
|
|
* @return {Object} The control descriptor.
|
|
*/
|
|
function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
return {
|
|
type: DISPATCH,
|
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
actionName,
|
|
args
|
|
};
|
|
}
|
|
export const controls = {
|
|
select,
|
|
resolveSelect,
|
|
dispatch
|
|
};
|
|
export const builtinControls = {
|
|
[SELECT]: createRegistryControl(registry => ({
|
|
storeKey,
|
|
selectorName,
|
|
args
|
|
}) => registry.select(storeKey)[selectorName](...args)),
|
|
[RESOLVE_SELECT]: createRegistryControl(registry => ({
|
|
storeKey,
|
|
selectorName,
|
|
args
|
|
}) => {
|
|
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select';
|
|
return registry[method](storeKey)[selectorName](...args);
|
|
}),
|
|
[DISPATCH]: createRegistryControl(registry => ({
|
|
storeKey,
|
|
actionName,
|
|
args
|
|
}) => registry.dispatch(storeKey)[actionName](...args))
|
|
};
|
|
//# sourceMappingURL=controls.js.map
|