@wordpress/data
Version:
Data module for WordPress.
77 lines • 3.07 kB
TypeScript
/**
* Internal dependencies
*/
import type { select as globalSelect } from './select';
type RegistrySelector<Selector extends (...args: any[]) => any> = {
(...args: Parameters<Selector>): ReturnType<Selector>;
isRegistrySelector?: boolean;
registry?: any;
};
/**
* Creates a selector function that takes additional curried argument with the
* registry `select` function. While a regular selector has signature
* ```js
* ( state, ...selectorArgs ) => ( result )
* ```
* that allows to select data from the store's `state`, a registry selector
* has signature:
* ```js
* ( select ) => ( state, ...selectorArgs ) => ( result )
* ```
* that supports also selecting from other registered stores.
*
* @example
* ```js
* import { store as coreStore } from '@wordpress/core-data';
* import { store as editorStore } from '@wordpress/editor';
*
* const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
* return select( editorStore ).getCurrentPostId();
* } );
*
* const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
* // calling another registry selector just like any other function
* const postType = getCurrentPostType( state );
* const postId = getCurrentPostId( state );
* return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );
* } );
* ```
*
* Note how the `getCurrentPostId` selector can be called just like any other function,
* (it works even inside a regular non-registry selector) and we don't need to pass the
* registry as argument. The registry binding happens automatically when registering the selector
* with a store.
*
* @param registrySelector Function receiving a registry `select`
* function and returning a state selector.
*
* @return Registry selector that can be registered with a store.
*/
export declare function createRegistrySelector<Selector extends (...args: any[]) => any>(registrySelector: (select: typeof globalSelect) => Selector): RegistrySelector<Selector>;
/**
* Creates a control function that takes additional curried argument with the `registry` object.
* While a regular control has signature
* ```js
* ( action ) => ( iteratorOrPromise )
* ```
* where the control works with the `action` that it's bound to, a registry control has signature:
* ```js
* ( registry ) => ( action ) => ( iteratorOrPromise )
* ```
* A registry control is typically used to select data or dispatch an action to a registered
* store.
*
* When registering a control created with `createRegistryControl` with a store, the store
* knows which calling convention to use when executing the control.
*
* @param registryControl Function receiving a registry object and returning a control.
*
* @return Registry control that can be registered with a store.
*/
export declare function createRegistryControl<T extends (...args: any) => any>(registryControl: T & {
isRegistryControl?: boolean;
}): T & {
isRegistryControl?: boolean;
};
export {};
//# sourceMappingURL=factory.d.ts.map