[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> data-controls.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/compat get default export */
   8  /******/     (() => {
   9  /******/         // getDefaultExport function for compatibility with non-harmony modules
  10  /******/         __webpack_require__.n = (module) => {
  11  /******/             var getter = module && module.__esModule ?
  12  /******/                 () => (module['default']) :
  13  /******/                 () => (module);
  14  /******/             __webpack_require__.d(getter, { a: getter });
  15  /******/             return getter;
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/define property getters */
  20  /******/     (() => {
  21  /******/         // define getter functions for harmony exports
  22  /******/         __webpack_require__.d = (exports, definition) => {
  23  /******/             for(var key in definition) {
  24  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26  /******/                 }
  27  /******/             }
  28  /******/         };
  29  /******/     })();
  30  /******/     
  31  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  32  /******/     (() => {
  33  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  34  /******/     })();
  35  /******/     
  36  /******/     /* webpack/runtime/make namespace object */
  37  /******/     (() => {
  38  /******/         // define __esModule on exports
  39  /******/         __webpack_require__.r = (exports) => {
  40  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42  /******/             }
  43  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  44  /******/         };
  45  /******/     })();
  46  /******/     
  47  /************************************************************************/
  48  var __webpack_exports__ = {};
  49  // ESM COMPAT FLAG
  50  __webpack_require__.r(__webpack_exports__);
  51  
  52  // EXPORTS
  53  __webpack_require__.d(__webpack_exports__, {
  54    __unstableAwaitPromise: () => (/* binding */ __unstableAwaitPromise),
  55    apiFetch: () => (/* binding */ apiFetch),
  56    controls: () => (/* binding */ controls),
  57    dispatch: () => (/* binding */ dispatch),
  58    select: () => (/* binding */ build_module_select),
  59    syncSelect: () => (/* binding */ syncSelect)
  60  });
  61  
  62  ;// external ["wp","apiFetch"]
  63  const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
  64  var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
  65  ;// external ["wp","data"]
  66  const external_wp_data_namespaceObject = window["wp"]["data"];
  67  ;// external ["wp","deprecated"]
  68  const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
  69  var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
  70  ;// ./node_modules/@wordpress/data-controls/build-module/index.js
  71  /**
  72   * WordPress dependencies
  73   */
  74  
  75  
  76  
  77  /**
  78   * Dispatches a control action for triggering an api fetch call.
  79   *
  80   * @param {Object} request Arguments for the fetch request.
  81   *
  82   * @example
  83   * ```js
  84   * import { apiFetch } from '@wordpress/data-controls';
  85   *
  86   * // Action generator using apiFetch
  87   * export function* myAction() {
  88   *     const path = '/v2/my-api/items';
  89   *     const items = yield apiFetch( { path } );
  90   *     // do something with the items.
  91   * }
  92   * ```
  93   *
  94   * @return {Object} The control descriptor.
  95   */
  96  function apiFetch(request) {
  97    return {
  98      type: 'API_FETCH',
  99      request
 100    };
 101  }
 102  
 103  /**
 104   * Control for resolving a selector in a registered data store.
 105   * Alias for the `resolveSelect` built-in control in the `@wordpress/data` package.
 106   *
 107   * @param storeNameOrDescriptor The store object or identifier.
 108   * @param selectorName          The selector name.
 109   * @param args                  Arguments passed without change to the `@wordpress/data` control.
 110   */
 111  function build_module_select(storeNameOrDescriptor, selectorName, ...args) {
 112    external_wp_deprecated_default()('`select` control in `@wordpress/data-controls`', {
 113      since: '5.7',
 114      alternative: 'built-in `resolveSelect` control in `@wordpress/data`'
 115    });
 116    return external_wp_data_namespaceObject.controls.resolveSelect(storeNameOrDescriptor, selectorName, ...args);
 117  }
 118  
 119  /**
 120   * Control for calling a selector in a registered data store.
 121   * Alias for the `select` built-in control in the `@wordpress/data` package.
 122   *
 123   * @param storeNameOrDescriptor The store object or identifier.
 124   * @param selectorName          The selector name.
 125   * @param args                  Arguments passed without change to the `@wordpress/data` control.
 126   */
 127  function syncSelect(storeNameOrDescriptor, selectorName, ...args) {
 128    external_wp_deprecated_default()('`syncSelect` control in `@wordpress/data-controls`', {
 129      since: '5.7',
 130      alternative: 'built-in `select` control in `@wordpress/data`'
 131    });
 132    return external_wp_data_namespaceObject.controls.select(storeNameOrDescriptor, selectorName, ...args);
 133  }
 134  
 135  /**
 136   * Control for dispatching an action in a registered data store.
 137   * Alias for the `dispatch` control in the `@wordpress/data` package.
 138   *
 139   * @param storeNameOrDescriptor The store object or identifier.
 140   * @param actionName            The action name.
 141   * @param args                  Arguments passed without change to the `@wordpress/data` control.
 142   */
 143  function dispatch(storeNameOrDescriptor, actionName, ...args) {
 144    external_wp_deprecated_default()('`dispatch` control in `@wordpress/data-controls`', {
 145      since: '5.7',
 146      alternative: 'built-in `dispatch` control in `@wordpress/data`'
 147    });
 148    return external_wp_data_namespaceObject.controls.dispatch(storeNameOrDescriptor, actionName, ...args);
 149  }
 150  
 151  /**
 152   * Dispatches a control action for awaiting on a promise to be resolved.
 153   *
 154   * @param {Object} promise Promise to wait for.
 155   *
 156   * @example
 157   * ```js
 158   * import { __unstableAwaitPromise } from '@wordpress/data-controls';
 159   *
 160   * // Action generator using apiFetch
 161   * export function* myAction() {
 162   *     const promise = getItemsAsync();
 163   *     const items = yield __unstableAwaitPromise( promise );
 164   *     // do something with the items.
 165   * }
 166   * ```
 167   *
 168   * @return {Object} The control descriptor.
 169   */
 170  const __unstableAwaitPromise = function (promise) {
 171    return {
 172      type: 'AWAIT_PROMISE',
 173      promise
 174    };
 175  };
 176  
 177  /**
 178   * The default export is what you use to register the controls with your custom
 179   * store.
 180   *
 181   * @example
 182   * ```js
 183   * // WordPress dependencies
 184   * import { controls } from '@wordpress/data-controls';
 185   * import { registerStore } from '@wordpress/data';
 186   *
 187   * // Internal dependencies
 188   * import reducer from './reducer';
 189   * import * as selectors from './selectors';
 190   * import * as actions from './actions';
 191   * import * as resolvers from './resolvers';
 192   *
 193   * registerStore( 'my-custom-store', {
 194   * reducer,
 195   * controls,
 196   * actions,
 197   * selectors,
 198   * resolvers,
 199   * } );
 200   * ```
 201   * @return {Object} An object for registering the default controls with the
 202   * store.
 203   */
 204  const controls = {
 205    AWAIT_PROMISE: ({
 206      promise
 207    }) => promise,
 208    API_FETCH({
 209      request
 210    }) {
 211      return external_wp_apiFetch_default()(request);
 212    }
 213  };
 214  
 215  (window.wp = window.wp || {}).dataControls = __webpack_exports__;
 216  /******/ })()
 217  ;


Generated : Sun Dec 22 08:20:01 2024 Cross-referenced by PHPXref