UNPKG

@wordpress/data-controls

Version:
111 lines 3.75 kB
import type { StoreDescriptor } from '@wordpress/data'; import type { APIFetchOptions } from '@wordpress/api-fetch'; /** * Dispatches a control action for triggering an api fetch call. * * @param {Object} request Arguments for the fetch request. * * @example * ```js * import { apiFetch } from '@wordpress/data-controls'; * * // Action generator using apiFetch * export function* myAction() { * const path = '/v2/my-api/items'; * const items = yield apiFetch( { path } ); * // do something with the items. * } * ``` * * @return {Object} The control descriptor. */ export declare function apiFetch(request: APIFetchOptions): { type: string; request: import("@wordpress/api-fetch/build-types/types").APIFetchOptions; }; /** * Control for resolving a selector in a registered data store. * Alias for the `resolveSelect` built-in control in the `@wordpress/data` package. * * @param storeNameOrDescriptor The store object or identifier. * @param selectorName The selector name. * @param args Arguments passed without change to the `@wordpress/data` control. */ export declare function select(storeNameOrDescriptor: string | StoreDescriptor, selectorName: string, ...args: any[]): Object; /** * Control for calling a selector in a registered data store. * Alias for the `select` built-in control in the `@wordpress/data` package. * * @param storeNameOrDescriptor The store object or identifier. * @param selectorName The selector name. * @param args Arguments passed without change to the `@wordpress/data` control. */ export declare function syncSelect(storeNameOrDescriptor: string | StoreDescriptor, selectorName: string, ...args: any[]): Object; /** * Control for dispatching an action in a registered data store. * Alias for the `dispatch` control in the `@wordpress/data` package. * * @param storeNameOrDescriptor The store object or identifier. * @param actionName The action name. * @param args Arguments passed without change to the `@wordpress/data` control. */ export declare function dispatch(storeNameOrDescriptor: string | StoreDescriptor, actionName: string, ...args: any[]): Object; /** * Dispatches a control action for awaiting on a promise to be resolved. * * @param {Object} promise Promise to wait for. * * @example * ```js * import { __unstableAwaitPromise } from '@wordpress/data-controls'; * * // Action generator using apiFetch * export function* myAction() { * const promise = getItemsAsync(); * const items = yield __unstableAwaitPromise( promise ); * // do something with the items. * } * ``` * * @return {Object} The control descriptor. */ export declare const __unstableAwaitPromise: <T>(promise: Promise<T>) => { type: string; promise: Promise<T>; }; /** * The default export is what you use to register the controls with your custom * store. * * @example * ```js * // WordPress dependencies * import { controls } from '@wordpress/data-controls'; * import { registerStore } from '@wordpress/data'; * * // Internal dependencies * import reducer from './reducer'; * import * as selectors from './selectors'; * import * as actions from './actions'; * import * as resolvers from './resolvers'; * * registerStore( 'my-custom-store', { * reducer, * controls, * actions, * selectors, * resolvers, * } ); * ``` * @return {Object} An object for registering the default controls with the * store. */ export declare const controls: { AWAIT_PROMISE<T>({ promise }: { promise: Promise<T>; }): Promise<T>; API_FETCH({ request }: { request: APIFetchOptions; }): Promise<unknown>; }; //# sourceMappingURL=index.d.ts.map