data-controls.js 6.8 KB

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