[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

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

   1  this["wp"] = this["wp"] || {}; this["wp"]["dataControls"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 317);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 17:
  91  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  92  
  93  "use strict";
  94  
  95  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  96  function _arrayWithoutHoles(arr) {
  97    if (Array.isArray(arr)) {
  98      for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  99        arr2[i] = arr[i];
 100      }
 101  
 102      return arr2;
 103    }
 104  }
 105  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
 106  var iterableToArray = __webpack_require__(30);
 107  
 108  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
 109  function _nonIterableSpread() {
 110    throw new TypeError("Invalid attempt to spread non-iterable instance");
 111  }
 112  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
 113  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _toConsumableArray; });
 114  
 115  
 116  
 117  function _toConsumableArray(arr) {
 118    return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || _nonIterableSpread();
 119  }
 120  
 121  /***/ }),
 122  
 123  /***/ 30:
 124  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 125  
 126  "use strict";
 127  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; });
 128  function _iterableToArray(iter) {
 129    if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
 130  }
 131  
 132  /***/ }),
 133  
 134  /***/ 317:
 135  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 136  
 137  "use strict";
 138  __webpack_require__.r(__webpack_exports__);
 139  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "apiFetch", function() { return apiFetch; });
 140  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "select", function() { return select; });
 141  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dispatch", function() { return dispatch; });
 142  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "controls", function() { return controls; });
 143  /* harmony import */ var _babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17);
 144  /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(34);
 145  /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__);
 146  /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4);
 147  /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__);
 148  
 149  
 150  /**
 151   * WordPress dependencies
 152   */
 153  
 154  
 155  /**
 156   * Dispatches a control action for triggering an api fetch call.
 157   *
 158   * @param {Object} request Arguments for the fetch request.
 159   *
 160   * @example
 161   * ```js
 162   * import { apiFetch } from '@wordpress/data-controls';
 163   *
 164   * // Action generator using apiFetch
 165   * export function* myAction {
 166   *        const path = '/v2/my-api/items';
 167   *        const items = yield apiFetch( { path } );
 168   *        // do something with the items.
 169   * }
 170   * ```
 171   *
 172   * @return {Object} The control descriptor.
 173   */
 174  
 175  var apiFetch = function apiFetch(request) {
 176    return {
 177      type: 'API_FETCH',
 178      request: request
 179    };
 180  };
 181  /**
 182   * Dispatches a control action for triggering a registry select.
 183   *
 184   * Note: when this control action is handled, it automatically considers
 185   * selectors that may have a resolver. It will await and return the resolved
 186   * value when the selector has not been resolved yet.
 187   *
 188   * @param {string} storeKey      The key for the store the selector belongs to
 189   * @param {string} selectorName  The name of the selector
 190   * @param {Array}  args          Arguments for the select.
 191   *
 192   * @example
 193   * ```js
 194   * import { select } from '@wordpress/data-controls';
 195   *
 196   * // Action generator using select
 197   * export function* myAction {
 198   *        const isSidebarOpened = yield select( 'core/edit-post', 'isEditorSideBarOpened' );
 199   *        // do stuff with the result from the select.
 200   * }
 201   * ```
 202   *
 203   * @return {Object} The control descriptor.
 204   */
 205  
 206  function select(storeKey, selectorName) {
 207    for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
 208      args[_key - 2] = arguments[_key];
 209    }
 210  
 211    return {
 212      type: 'SELECT',
 213      storeKey: storeKey,
 214      selectorName: selectorName,
 215      args: args
 216    };
 217  }
 218  /**
 219   * Dispatches a control action for triggering a registry dispatch.
 220   *
 221   * @param {string} storeKey    The key for the store the action belongs to
 222   * @param {string} actionName  The name of the action to dispatch
 223   * @param {Array}  args        Arguments for the dispatch action.
 224   *
 225   * @example
 226   * ```js
 227   * import { dispatch } from '@wordpress/data-controls';
 228   *
 229   * // Action generator using dispatch
 230   * export function* myAction {
 231   *   yield dispatch( 'core/edit-post' ).togglePublishSidebar();
 232   *   // do some other things.
 233   * }
 234   * ```
 235   *
 236   * @return {Object}  The control descriptor.
 237   */
 238  
 239  function dispatch(storeKey, actionName) {
 240    for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
 241      args[_key2 - 2] = arguments[_key2];
 242    }
 243  
 244    return {
 245      type: 'DISPATCH',
 246      storeKey: storeKey,
 247      actionName: actionName,
 248      args: args
 249    };
 250  }
 251  /**
 252   * Utility for returning a promise that handles a selector with a resolver.
 253   *
 254   * @param {Object} registry             The data registry.
 255   * @param {Object} options
 256   * @param {string} options.storeKey     The store the selector belongs to
 257   * @param {string} options.selectorName The selector name
 258   * @param {Array}  options.args         The arguments fed to the selector
 259   *
 260   * @return {Promise}  A promise for resolving the given selector.
 261   */
 262  
 263  var resolveSelect = function resolveSelect(registry, _ref) {
 264    var storeKey = _ref.storeKey,
 265        selectorName = _ref.selectorName,
 266        args = _ref.args;
 267    return new Promise(function (resolve) {
 268      var hasFinished = function hasFinished() {
 269        return registry.select('core/data').hasFinishedResolution(storeKey, selectorName, args);
 270      };
 271  
 272      var getResult = function getResult() {
 273        return registry.select(storeKey)[selectorName].apply(null, args);
 274      }; // trigger the selector (to trigger the resolver)
 275  
 276  
 277      var result = getResult();
 278  
 279      if (hasFinished()) {
 280        return resolve(result);
 281      }
 282  
 283      var unsubscribe = registry.subscribe(function () {
 284        if (hasFinished()) {
 285          unsubscribe();
 286          resolve(getResult());
 287        }
 288      });
 289    });
 290  };
 291  /**
 292   * The default export is what you use to register the controls with your custom
 293   * store.
 294   *
 295   * @example
 296   * ```js
 297   * // WordPress dependencies
 298   * import { controls } from '@wordpress/data-controls';
 299   * import { registerStore } from '@wordpress/data';
 300   *
 301   * // Internal dependencies
 302   * import reducer from './reducer';
 303   * import * as selectors from './selectors';
 304   * import * as actions from './actions';
 305   * import * as resolvers from './resolvers';
 306   *
 307   * registerStore ( 'my-custom-store', {
 308   *     reducer,
 309   *     controls,
 310   *     actions,
 311   *     selectors,
 312   *     resolvers,
 313   * } );
 314   * ```
 315   *
 316   * @return {Object} An object for registering the default controls with the
 317   *                  store.
 318   */
 319  
 320  
 321  var controls = {
 322    API_FETCH: function API_FETCH(_ref2) {
 323      var request = _ref2.request;
 324      return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default()(request);
 325    },
 326    SELECT: Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["createRegistryControl"])(function (registry) {
 327      return function (_ref3) {
 328        var _registry$select;
 329  
 330        var storeKey = _ref3.storeKey,
 331            selectorName = _ref3.selectorName,
 332            args = _ref3.args;
 333        return registry.select(storeKey)[selectorName].hasResolver ? resolveSelect(registry, {
 334          storeKey: storeKey,
 335          selectorName: selectorName,
 336          args: args
 337        }) : (_registry$select = registry.select(storeKey))[selectorName].apply(_registry$select, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(args));
 338      };
 339    }),
 340    DISPATCH: Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["createRegistryControl"])(function (registry) {
 341      return function (_ref4) {
 342        var _registry$dispatch;
 343  
 344        var storeKey = _ref4.storeKey,
 345            actionName = _ref4.actionName,
 346            args = _ref4.args;
 347        return (_registry$dispatch = registry.dispatch(storeKey))[actionName].apply(_registry$dispatch, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(args));
 348      };
 349    })
 350  };
 351  
 352  
 353  /***/ }),
 354  
 355  /***/ 34:
 356  /***/ (function(module, exports) {
 357  
 358  (function() { module.exports = this["wp"]["apiFetch"]; }());
 359  
 360  /***/ }),
 361  
 362  /***/ 4:
 363  /***/ (function(module, exports) {
 364  
 365  (function() { module.exports = this["wp"]["data"]; }());
 366  
 367  /***/ })
 368  
 369  /******/ });


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7