PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/data/index.js +851 -402 12.6.0 → 14.5.2 View file →
@@ -1,9 +1,9 @@
1 -/******/ (function() { // webpackBootstrap
1 +/******/ (() => { // webpackBootstrap
2 2 /******/ var __webpack_modules__ = ({
3 3
4 -/***/ 3909:
5 -/***/ (function(module) {
4 +/***/ 2167:
5 +/***/ ((module) => {
6 6
7 7 "use strict";
8 8
9 9
@@ -315,10 +315,10 @@
315 315
316 316
317 317 /***/ }),
318 318
319 -/***/ 9884:
320 -/***/ (function(module) {
319 +/***/ 9125:
320 +/***/ ((module) => {
321 321
322 322 function combineReducers( reducers ) {
323 323 var keys = Object.keys( reducers ),
324 324 getNextState;
@@ -402,23 +402,23 @@
402 402 /******/ }
403 403 /******/
404 404 /************************************************************************/
405 405 /******/ /* webpack/runtime/compat get default export */
406 -/******/ !function() {
406 +/******/ (() => {
407 407 /******/ // getDefaultExport function for compatibility with non-harmony modules
408 -/******/ __webpack_require__.n = function(module) {
408 +/******/ __webpack_require__.n = (module) => {
409 409 /******/ var getter = module && module.__esModule ?
410 -/******/ function() { return module['default']; } :
411 -/******/ function() { return module; };
410 +/******/ () => (module['default']) :
411 +/******/ () => (module);
412 412 /******/ __webpack_require__.d(getter, { a: getter });
413 413 /******/ return getter;
414 414 /******/ };
415 -/******/ }();
415 +/******/ })();
416 416 /******/
417 417 /******/ /* webpack/runtime/define property getters */
418 -/******/ !function() {
418 +/******/ (() => {
419 419 /******/ // define getter functions for harmony exports
420 -/******/ __webpack_require__.d = function(exports, definition) {
420 +/******/ __webpack_require__.d = (exports, definition) => {
421 421 /******/ for(var key in definition) {
422 422 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
423 423 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
424 424 /******/ }
@@ -423,30 +423,30 @@
423 423 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
424 424 /******/ }
425 425 /******/ }
426 426 /******/ };
427 -/******/ }();
427 +/******/ })();
428 428 /******/
429 429 /******/ /* webpack/runtime/hasOwnProperty shorthand */
430 -/******/ !function() {
431 -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
432 -/******/ }();
430 +/******/ (() => {
431 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
432 +/******/ })();
433 433 /******/
434 434 /******/ /* webpack/runtime/make namespace object */
435 -/******/ !function() {
435 +/******/ (() => {
436 436 /******/ // define __esModule on exports
437 -/******/ __webpack_require__.r = function(exports) {
437 +/******/ __webpack_require__.r = (exports) => {
438 438 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
439 439 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
440 440 /******/ }
441 441 /******/ Object.defineProperty(exports, '__esModule', { value: true });
442 442 /******/ };
443 -/******/ }();
443 +/******/ })();
444 444 /******/
445 445 /************************************************************************/
446 446 var __webpack_exports__ = {};
447 447 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
448 -!function() {
448 +(() => {
449 449 "use strict";
450 450 // ESM COMPAT FLAG
451 451 __webpack_require__.r(__webpack_exports__);
452 452
@@ -451,32 +451,34 @@
451 451 __webpack_require__.r(__webpack_exports__);
452 452
453 453 // EXPORTS
454 454 __webpack_require__.d(__webpack_exports__, {
455 - "AsyncModeProvider": function() { return /* reexport */ async_mode_provider_context; },
456 - "RegistryConsumer": function() { return /* reexport */ RegistryConsumer; },
457 - "RegistryProvider": function() { return /* reexport */ context; },
458 - "combineReducers": function() { return /* reexport */ (turbo_combine_reducers_default()); },
459 - "controls": function() { return /* reexport */ controls; },
460 - "createReduxStore": function() { return /* reexport */ createReduxStore; },
461 - "createRegistry": function() { return /* reexport */ createRegistry; },
462 - "createRegistryControl": function() { return /* reexport */ createRegistryControl; },
463 - "createRegistrySelector": function() { return /* reexport */ createRegistrySelector; },
464 - "dispatch": function() { return /* binding */ build_module_dispatch; },
465 - "plugins": function() { return /* reexport */ plugins_namespaceObject; },
466 - "register": function() { return /* binding */ register; },
467 - "registerGenericStore": function() { return /* binding */ registerGenericStore; },
468 - "registerStore": function() { return /* binding */ registerStore; },
469 - "resolveSelect": function() { return /* binding */ build_module_resolveSelect; },
470 - "select": function() { return /* binding */ build_module_select; },
471 - "subscribe": function() { return /* binding */ subscribe; },
472 - "use": function() { return /* binding */ use; },
473 - "useDispatch": function() { return /* reexport */ use_dispatch; },
474 - "useRegistry": function() { return /* reexport */ useRegistry; },
475 - "useSelect": function() { return /* reexport */ useSelect; },
476 - "withDispatch": function() { return /* reexport */ with_dispatch; },
477 - "withRegistry": function() { return /* reexport */ with_registry; },
478 - "withSelect": function() { return /* reexport */ with_select; }
455 + "AsyncModeProvider": () => (/* reexport */ async_mode_provider_context),
456 + "RegistryConsumer": () => (/* reexport */ RegistryConsumer),
457 + "RegistryProvider": () => (/* reexport */ context),
458 + "combineReducers": () => (/* binding */ build_module_combineReducers),
459 + "controls": () => (/* reexport */ controls),
460 + "createReduxStore": () => (/* reexport */ createReduxStore),
461 + "createRegistry": () => (/* reexport */ createRegistry),
462 + "createRegistryControl": () => (/* reexport */ createRegistryControl),
463 + "createRegistrySelector": () => (/* reexport */ createRegistrySelector),
464 + "dispatch": () => (/* binding */ build_module_dispatch),
465 + "plugins": () => (/* reexport */ plugins_namespaceObject),
466 + "register": () => (/* binding */ register),
467 + "registerGenericStore": () => (/* binding */ registerGenericStore),
468 + "registerStore": () => (/* binding */ registerStore),
469 + "resolveSelect": () => (/* binding */ build_module_resolveSelect),
470 + "select": () => (/* binding */ build_module_select),
471 + "subscribe": () => (/* binding */ subscribe),
472 + "suspendSelect": () => (/* binding */ suspendSelect),
473 + "use": () => (/* binding */ use),
474 + "useDispatch": () => (/* reexport */ use_dispatch),
475 + "useRegistry": () => (/* reexport */ useRegistry),
476 + "useSelect": () => (/* reexport */ useSelect),
477 + "useSuspenseSelect": () => (/* reexport */ useSuspenseSelect),
478 + "withDispatch": () => (/* reexport */ with_dispatch),
479 + "withRegistry": () => (/* reexport */ with_registry),
480 + "withSelect": () => (/* reexport */ with_select)
479 481 });
480 482
481 483 // NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/selectors.js
482 484 var selectors_namespaceObject = {};
@@ -481,13 +483,16 @@
481 483 // NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/selectors.js
482 484 var selectors_namespaceObject = {};
483 485 __webpack_require__.r(selectors_namespaceObject);
484 486 __webpack_require__.d(selectors_namespaceObject, {
485 - "getCachedResolvers": function() { return getCachedResolvers; },
486 - "getIsResolving": function() { return getIsResolving; },
487 - "hasFinishedResolution": function() { return hasFinishedResolution; },
488 - "hasStartedResolution": function() { return hasStartedResolution; },
489 - "isResolving": function() { return isResolving; }
487 + "getCachedResolvers": () => (getCachedResolvers),
488 + "getIsResolving": () => (getIsResolving),
489 + "getResolutionError": () => (getResolutionError),
490 + "getResolutionState": () => (getResolutionState),
491 + "hasFinishedResolution": () => (hasFinishedResolution),
492 + "hasResolutionFailed": () => (hasResolutionFailed),
493 + "hasStartedResolution": () => (hasStartedResolution),
494 + "isResolving": () => (isResolving)
490 495 });
491 496
492 497 // NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/actions.js
493 498 var actions_namespaceObject = {};
@@ -492,15 +497,17 @@
492 497 // NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/actions.js
493 498 var actions_namespaceObject = {};
494 499 __webpack_require__.r(actions_namespaceObject);
495 500 __webpack_require__.d(actions_namespaceObject, {
496 - "finishResolution": function() { return finishResolution; },
497 - "finishResolutions": function() { return finishResolutions; },
498 - "invalidateResolution": function() { return invalidateResolution; },
499 - "invalidateResolutionForStore": function() { return invalidateResolutionForStore; },
500 - "invalidateResolutionForStoreSelector": function() { return invalidateResolutionForStoreSelector; },
501 - "startResolution": function() { return startResolution; },
502 - "startResolutions": function() { return startResolutions; }
501 + "failResolution": () => (failResolution),
502 + "failResolutions": () => (failResolutions),
503 + "finishResolution": () => (finishResolution),
504 + "finishResolutions": () => (finishResolutions),
505 + "invalidateResolution": () => (invalidateResolution),
506 + "invalidateResolutionForStore": () => (invalidateResolutionForStore),
507 + "invalidateResolutionForStoreSelector": () => (invalidateResolutionForStoreSelector),
508 + "startResolution": () => (startResolution),
509 + "startResolutions": () => (startResolutions)
503 510 });
504 511
505 512 // NAMESPACE OBJECT: ./packages/data/build-module/plugins/index.js
506 513 var plugins_namespaceObject = {};
@@ -505,18 +512,18 @@
505 512 // NAMESPACE OBJECT: ./packages/data/build-module/plugins/index.js
506 513 var plugins_namespaceObject = {};
507 514 __webpack_require__.r(plugins_namespaceObject);
508 515 __webpack_require__.d(plugins_namespaceObject, {
509 - "persistence": function() { return persistence; }
516 + "persistence": () => (persistence)
510 517 });
511 518
512 519 // EXTERNAL MODULE: ./node_modules/turbo-combine-reducers/index.js
513 -var turbo_combine_reducers = __webpack_require__(9884);
520 +var turbo_combine_reducers = __webpack_require__(9125);
514 521 var turbo_combine_reducers_default = /*#__PURE__*/__webpack_require__.n(turbo_combine_reducers);
515 522 ;// CONCATENATED MODULE: external "lodash"
516 -var external_lodash_namespaceObject = window["lodash"];
523 +const external_lodash_namespaceObject = window["lodash"];
517 524 ;// CONCATENATED MODULE: external ["wp","deprecated"]
518 -var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
525 +const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
519 526 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
520 527 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
521 528 function _defineProperty(obj, key, value) {
522 529 if (key in obj) {
@@ -1242,13 +1249,15 @@
1242 1249
1243 1250
1244 1251
1245 1252 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js
1246 -var equivalent_key_map = __webpack_require__(3909);
1253 +var equivalent_key_map = __webpack_require__(2167);
1247 1254 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map);
1248 1255 ;// CONCATENATED MODULE: external ["wp","reduxRoutine"]
1249 -var external_wp_reduxRoutine_namespaceObject = window["wp"]["reduxRoutine"];
1256 +const external_wp_reduxRoutine_namespaceObject = window["wp"]["reduxRoutine"];
1250 1257 var external_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_wp_reduxRoutine_namespaceObject);
1258 +;// CONCATENATED MODULE: external ["wp","compose"]
1259 +const external_wp_compose_namespaceObject = window["wp"]["compose"];
1251 1260 ;// CONCATENATED MODULE: ./packages/data/build-module/factory.js
1252 1261 /**
1253 1262 * Creates a selector function that takes additional curried argument with the
1254 1263 * registry `select` function. While a regular selector has signature
@@ -1263,10 +1272,13 @@
1263 1272 * that supports also selecting from other registered stores.
1264 1273 *
1265 1274 * @example
1266 1275 * ```js
1276 + * import { store as coreStore } from '@wordpress/core-data';
1277 + * import { store as editorStore } from '@wordpress/editor';
1278 + *
1267 1279 * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
1268 - * return select( 'core/editor' ).getCurrentPostId();
1280 + * return select( editorStore ).getCurrentPostId();
1269 1281 * } );
1270 1282 *
1271 1283 * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
1272 1284 * // calling another registry selector just like any other function
@@ -1271,9 +1283,9 @@
1271 1283 * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
1272 1284 * // calling another registry selector just like any other function
1273 1285 * const postType = getCurrentPostType( state );
1274 1286 * const postId = getCurrentPostId( state );
1275 - * return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );
1287 + * return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );
1276 1288 * } );
1277 1289 * ```
1278 1290 *
1279 1291 * Note how the `getCurrentPostId` selector can be called just like any other function,
@@ -1286,9 +1298,9 @@
1286 1298 *
1287 1299 * @return {Function} Registry selector that can be registered with a store.
1288 1300 */
1289 1301 function createRegistrySelector(registrySelector) {
1290 - // create a selector function that is bound to the registry referenced by `selector.registry`
1302 + // Create a selector function that is bound to the registry referenced by `selector.registry`
1291 1303 // and that has the same API as a regular selector. Binding it in such a way makes it
1292 1304 // possible to call the selector directly from another selector.
1293 1305 const selector = function () {
1294 1306 return registrySelector(selector.registry.select)(...arguments);
@@ -1329,24 +1341,23 @@
1329 1341 function createRegistryControl(registryControl) {
1330 1342 registryControl.isRegistryControl = true;
1331 1343 return registryControl;
1332 1344 }
1333 -//# sourceMappingURL=factory.js.map
1345 +
1334 1346 ;// CONCATENATED MODULE: ./packages/data/build-module/controls.js
1335 1347 /**
1336 - * External dependencies
1337 - */
1338 -
1339 -/**
1340 1348 * Internal dependencies
1341 1349 */
1342 1350
1343 -
1344 1351 /** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
1345 1352
1346 1353 const SELECT = '@@data/SELECT';
1347 1354 const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
1348 1355 const DISPATCH = '@@data/DISPATCH';
1356 +
1357 +function isObject(object) {
1358 + return object !== null && typeof object === 'object';
1359 +}
1349 1360 /**
1350 1361 * Dispatches a control action for triggering a synchronous registry select.
1351 1362 *
1352 1363 * Note: This control synchronously returns the current selector value, triggering the
@@ -1369,8 +1380,9 @@
1369 1380 *
1370 1381 * @return {Object} The control descriptor.
1371 1382 */
1372 1383
1384 +
1373 1385 function controls_select(storeNameOrDescriptor, selectorName) {
1374 1386 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1375 1387 args[_key - 2] = arguments[_key];
1376 1388 }
@@ -1376,9 +1388,9 @@
1376 1388 }
1377 1389
1378 1390 return {
1379 1391 type: SELECT,
1380 - storeKey: (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1392 + storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1381 1393 selectorName,
1382 1394 args
1383 1395 };
1384 1396 }
@@ -1414,9 +1426,9 @@
1414 1426 }
1415 1427
1416 1428 return {
1417 1429 type: RESOLVE_SELECT,
1418 - storeKey: (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1430 + storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1419 1431 selectorName,
1420 1432 args
1421 1433 };
1422 1434 }
@@ -1448,9 +1460,9 @@
1448 1460 }
1449 1461
1450 1462 return {
1451 1463 type: DISPATCH,
1452 - storeKey: (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1464 + storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
1453 1465 actionName,
1454 1466 args
1455 1467 };
1456 1468 }
@@ -1486,9 +1498,9 @@
1486 1498 } = _ref3;
1487 1499 return registry.dispatch(storeKey)[actionName](...args);
1488 1500 })
1489 1501 };
1490 -//# sourceMappingURL=controls.js.map
1502 +
1491 1503 ;// CONCATENATED MODULE: ./node_modules/is-promise/index.mjs
1492 1504 function isPromise(obj) {
1493 1505 return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
1494 1506 }
@@ -1515,10 +1527,10 @@
1515 1527
1516 1528 return next(action);
1517 1529 };
1518 1530
1519 -/* harmony default export */ var promise_middleware = (promiseMiddleware);
1520 -//# sourceMappingURL=promise-middleware.js.map
1531 +/* harmony default export */ const promise_middleware = (promiseMiddleware);
1532 +
1521 1533 ;// CONCATENATED MODULE: ./packages/data/build-module/store/index.js
1522 1534 const coreDataStore = {
1523 1535 name: 'core/data',
1524 1536
@@ -1559,10 +1571,10 @@
1559 1571 };
1560 1572 }
1561 1573
1562 1574 };
1563 -/* harmony default export */ var store = (coreDataStore);
1564 -//# sourceMappingURL=index.js.map
1575 +/* harmony default export */ const store = (coreDataStore);
1576 +
1565 1577 ;// CONCATENATED MODULE: ./packages/data/build-module/resolvers-cache-middleware.js
1566 1578 /**
1567 1579 * External dependencies
1568 1580 */
@@ -1596,11 +1608,11 @@
1596 1608 }
1597 1609
1598 1610 resolversByArgs.forEach((value, args) => {
1599 1611 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.
1600 - // If the value is false it means this resolver has finished its resolution which means we need to invalidate it,
1601 - // if it's true it means it's inflight and the invalidation is not necessary.
1602 - if (value !== false || !resolver.shouldInvalidate(action, ...args)) {
1612 + // If the value is "finished" or "error" it means this resolver has finished its resolution which means we need
1613 + // to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.
1614 + if ((value === null || value === void 0 ? void 0 : value.status) !== 'finished' && (value === null || value === void 0 ? void 0 : value.status) !== 'error' || !resolver.shouldInvalidate(action, ...args)) {
1603 1615 return;
1604 1616 } // Trigger cache invalidation
1605 1617
1606 1618
@@ -1609,10 +1621,10 @@
1609 1621 });
1610 1622 return next(action);
1611 1623 };
1612 1624
1613 -/* harmony default export */ var resolvers_cache_middleware = (createResolversCacheMiddleware);
1614 -//# sourceMappingURL=resolvers-cache-middleware.js.map
1625 +/* harmony default export */ const resolvers_cache_middleware = (createResolversCacheMiddleware);
1626 +
1615 1627 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/thunk-middleware.js
1616 1628 function createThunkMiddleware(args) {
1617 1629 return () => next => action => {
1618 1630 if (typeof action === 'function') {
@@ -1621,32 +1633,26 @@
1621 1633
1622 1634 return next(action);
1623 1635 };
1624 1636 }
1625 -//# sourceMappingURL=thunk-middleware.js.map
1637 +
1626 1638 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/utils.js
1627 1639 /**
1640 + * External dependencies
1641 + */
1642 +
1643 +/**
1628 1644 * Higher-order reducer creator which creates a combined reducer object, keyed
1629 1645 * by a property on the action object.
1630 1646 *
1631 - * @template {any} TState
1632 - * @template {import('redux').AnyAction} TAction
1633 - *
1634 - * @param {string} actionProperty Action property by which to key object.
1635 - *
1636 - * @return {(reducer: import('redux').Reducer<TState, TAction>) => import('redux').Reducer<Record<string, TState>, TAction>} Higher-order reducer.
1647 + * @param actionProperty Action property by which to key object.
1648 + * @return Higher-order reducer.
1637 1649 */
1638 1650 const onSubKey = actionProperty => reducer => function () {
1639 - let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
1640 - /** @type {Record<string, TState>} */
1641 - {};
1651 + let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1642 1652 let action = arguments.length > 1 ? arguments[1] : undefined;
1643 1653 // Retrieve subkey from action. Do not track if undefined; useful for cases
1644 1654 // where reducer is scoped by action shape.
1645 -
1646 - /** @type {keyof state} */
1647 -
1648 - /* eslint-enable jsdoc/no-undefined-types */
1649 1655 const key = action[actionProperty];
1650 1656
1651 1657 if (key === undefined) {
1652 1658 return state;
@@ -1663,9 +1669,31 @@
1663 1669 return { ...state,
1664 1670 [key]: nextKeyState
1665 1671 };
1666 1672 };
1667 -//# sourceMappingURL=utils.js.map
1673 +/**
1674 + * Normalize selector argument array by defaulting `undefined` value to an empty array
1675 + * and removing trailing `undefined` values.
1676 + *
1677 + * @param args Selector argument array
1678 + * @return Normalized state key array
1679 + */
1680 +
1681 +function selectorArgsToStateKey(args) {
1682 + if (args === undefined || args === null) {
1683 + return [];
1684 + }
1685 +
1686 + const len = args.length;
1687 + let idx = len;
1688 +
1689 + while (idx > 0 && args[idx - 1] === undefined) {
1690 + idx--;
1691 + }
1692 +
1693 + return idx === len ? args : args.slice(0, idx);
1694 +}
1695 +
1668 1696 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/reducer.js
1669 1697 /**
1670 1698 * External dependencies
1671 1699 */
@@ -1670,9 +1698,8 @@
1670 1698 * External dependencies
1671 1699 */
1672 1700
1673 1701
1674 -
1675 1702 /**
1676 1703 * Internal dependencies
1677 1704 */
1678 1705
@@ -1688,33 +1715,84 @@
1688 1715 let action = arguments.length > 1 ? arguments[1] : undefined;
1689 1716
1690 1717 switch (action.type) {
1691 1718 case 'START_RESOLUTION':
1719 + {
1720 + const nextState = new (equivalent_key_map_default())(state);
1721 + nextState.set(selectorArgsToStateKey(action.args), {
1722 + status: 'resolving'
1723 + });
1724 + return nextState;
1725 + }
1726 +
1692 1727 case 'FINISH_RESOLUTION':
1693 1728 {
1694 - const isStarting = action.type === 'START_RESOLUTION';
1695 1729 const nextState = new (equivalent_key_map_default())(state);
1696 - nextState.set(action.args, isStarting);
1730 + nextState.set(selectorArgsToStateKey(action.args), {
1731 + status: 'finished'
1732 + });
1697 1733 return nextState;
1698 1734 }
1699 1735
1736 + case 'FAIL_RESOLUTION':
1737 + {
1738 + const nextState = new (equivalent_key_map_default())(state);
1739 + nextState.set(selectorArgsToStateKey(action.args), {
1740 + status: 'error',
1741 + error: action.error
1742 + });
1743 + return nextState;
1744 + }
1745 +
1700 1746 case 'START_RESOLUTIONS':
1747 + {
1748 + const nextState = new (equivalent_key_map_default())(state);
1749 +
1750 + for (const resolutionArgs of action.args) {
1751 + nextState.set(selectorArgsToStateKey(resolutionArgs), {
1752 + status: 'resolving'
1753 + });
1754 + }
1755 +
1756 + return nextState;
1757 + }
1758 +
1701 1759 case 'FINISH_RESOLUTIONS':
1702 1760 {
1703 - const isStarting = action.type === 'START_RESOLUTIONS';
1704 1761 const nextState = new (equivalent_key_map_default())(state);
1705 1762
1706 1763 for (const resolutionArgs of action.args) {
1707 - nextState.set(resolutionArgs, isStarting);
1764 + nextState.set(selectorArgsToStateKey(resolutionArgs), {
1765 + status: 'finished'
1766 + });
1708 1767 }
1709 1768
1710 1769 return nextState;
1711 1770 }
1712 1771
1772 + case 'FAIL_RESOLUTIONS':
1773 + {
1774 + const nextState = new (equivalent_key_map_default())(state);
1775 + action.args.forEach((resolutionArgs, idx) => {
1776 + const resolutionState = {
1777 + status: 'error',
1778 + error: undefined
1779 + };
1780 + const error = action.errors[idx];
1781 +
1782 + if (error) {
1783 + resolutionState.error = error;
1784 + }
1785 +
1786 + nextState.set(selectorArgsToStateKey(resolutionArgs), resolutionState);
1787 + });
1788 + return nextState;
1789 + }
1790 +
1713 1791 case 'INVALIDATE_RESOLUTION':
1714 1792 {
1715 1793 const nextState = new (equivalent_key_map_default())(state);
1716 - nextState.delete(action.args);
1794 + nextState.delete(selectorArgsToStateKey(action.args));
1717 1795 return nextState;
1718 1796 }
1719 1797 }
1720 1798
@@ -1739,14 +1817,26 @@
1739 1817 case 'INVALIDATE_RESOLUTION_FOR_STORE':
1740 1818 return {};
1741 1819
1742 1820 case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR':
1743 - return (0,external_lodash_namespaceObject.has)(state, [action.selectorName]) ? (0,external_lodash_namespaceObject.omit)(state, [action.selectorName]) : state;
1821 + {
1822 + if (action.selectorName in state) {
1823 + const {
1824 + [action.selectorName]: removedSelector,
1825 + ...restState
1826 + } = state;
1827 + return restState;
1828 + }
1744 1829
1830 + return state;
1831 + }
1832 +
1745 1833 case 'START_RESOLUTION':
1746 1834 case 'FINISH_RESOLUTION':
1835 + case 'FAIL_RESOLUTION':
1747 1836 case 'START_RESOLUTIONS':
1748 1837 case 'FINISH_RESOLUTIONS':
1838 + case 'FAIL_RESOLUTIONS':
1749 1839 case 'INVALIDATE_RESOLUTION':
1750 1840 return subKeysIsResolved(state, action);
1751 1841 }
1752 1842
@@ -1752,83 +1842,143 @@
1752 1842
1753 1843 return state;
1754 1844 };
1755 1845
1756 -/* harmony default export */ var metadata_reducer = (isResolved);
1757 -//# sourceMappingURL=reducer.js.map
1846 +/* harmony default export */ const metadata_reducer = (isResolved);
1847 +
1758 1848 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/selectors.js
1759 1849 /**
1760 1850 * External dependencies
1761 1851 */
1762 1852
1853 +/**
1854 + * Internal dependencies
1855 + */
1856 +
1857 +
1763 1858 /** @typedef {Record<string, import('./reducer').State>} State */
1764 1859
1860 +/** @typedef {import('./reducer').StateValue} StateValue */
1861 +
1862 +/** @typedef {import('./reducer').Status} Status */
1863 +
1765 1864 /**
1766 - * Returns the raw `isResolving` value for a given selector name,
1865 + * Returns the raw resolution state value for a given selector name,
1767 1866 * and arguments set. May be undefined if the selector has never been resolved
1768 1867 * or not resolved for the given set of arguments, otherwise true or false for
1769 1868 * resolution started and completed respectively.
1770 1869 *
1771 - * @param {State} state Data state.
1772 - * @param {string} selectorName Selector name.
1773 - * @param {unknown[]} args Arguments passed to selector.
1870 + * @param {State} state Data state.
1871 + * @param {string} selectorName Selector name.
1872 + * @param {unknown[]?} args Arguments passed to selector.
1774 1873 *
1775 - * @return {boolean | undefined} isResolving value.
1874 + * @return {StateValue|undefined} isResolving value.
1776 1875 */
1777 1876
1778 -function getIsResolving(state, selectorName, args) {
1877 +function getResolutionState(state, selectorName, args) {
1779 1878 const map = (0,external_lodash_namespaceObject.get)(state, [selectorName]);
1780 1879
1781 1880 if (!map) {
1782 - return undefined;
1881 + return;
1783 1882 }
1784 1883
1785 - return map.get(args);
1884 + return map.get(selectorArgsToStateKey(args));
1786 1885 }
1787 1886 /**
1887 + * Returns the raw `isResolving` value for a given selector name,
1888 + * and arguments set. May be undefined if the selector has never been resolved
1889 + * or not resolved for the given set of arguments, otherwise true or false for
1890 + * resolution started and completed respectively.
1891 + *
1892 + * @param {State} state Data state.
1893 + * @param {string} selectorName Selector name.
1894 + * @param {unknown[]?} args Arguments passed to selector.
1895 + *
1896 + * @return {boolean | undefined} isResolving value.
1897 + */
1898 +
1899 +function getIsResolving(state, selectorName, args) {
1900 + const resolutionState = getResolutionState(state, selectorName, args);
1901 + return resolutionState && resolutionState.status === 'resolving';
1902 +}
1903 +/**
1788 1904 * Returns true if resolution has already been triggered for a given
1789 1905 * selector name, and arguments set.
1790 1906 *
1791 - * @param {State} state Data state.
1792 - * @param {string} selectorName Selector name.
1793 - * @param {unknown[]} [args] Arguments passed to selector (default `[]`).
1907 + * @param {State} state Data state.
1908 + * @param {string} selectorName Selector name.
1909 + * @param {unknown[]?} args Arguments passed to selector.
1794 1910 *
1795 1911 * @return {boolean} Whether resolution has been triggered.
1796 1912 */
1797 1913
1798 -function hasStartedResolution(state, selectorName) {
1799 - let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1800 - return getIsResolving(state, selectorName, args) !== undefined;
1914 +function hasStartedResolution(state, selectorName, args) {
1915 + return getResolutionState(state, selectorName, args) !== undefined;
1801 1916 }
1802 1917 /**
1803 1918 * Returns true if resolution has completed for a given selector
1804 1919 * name, and arguments set.
1805 1920 *
1806 - * @param {State} state Data state.
1807 - * @param {string} selectorName Selector name.
1808 - * @param {unknown[]} [args] Arguments passed to selector.
1921 + * @param {State} state Data state.
1922 + * @param {string} selectorName Selector name.
1923 + * @param {unknown[]?} args Arguments passed to selector.
1809 1924 *
1810 1925 * @return {boolean} Whether resolution has completed.
1811 1926 */
1812 1927
1813 -function hasFinishedResolution(state, selectorName) {
1814 - let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1815 - return getIsResolving(state, selectorName, args) === false;
1928 +function hasFinishedResolution(state, selectorName, args) {
1929 + var _getResolutionState;
1930 +
1931 + const status = (_getResolutionState = getResolutionState(state, selectorName, args)) === null || _getResolutionState === void 0 ? void 0 : _getResolutionState.status;
1932 + return status === 'finished' || status === 'error';
1816 1933 }
1817 1934 /**
1935 + * Returns true if resolution has failed for a given selector
1936 + * name, and arguments set.
1937 + *
1938 + * @param {State} state Data state.
1939 + * @param {string} selectorName Selector name.
1940 + * @param {unknown[]?} args Arguments passed to selector.
1941 + *
1942 + * @return {boolean} Has resolution failed
1943 + */
1944 +
1945 +function hasResolutionFailed(state, selectorName, args) {
1946 + var _getResolutionState2;
1947 +
1948 + return ((_getResolutionState2 = getResolutionState(state, selectorName, args)) === null || _getResolutionState2 === void 0 ? void 0 : _getResolutionState2.status) === 'error';
1949 +}
1950 +/**
1951 + * Returns the resolution error for a given selector name, and arguments set.
1952 + * Note it may be of an Error type, but may also be null, undefined, or anything else
1953 + * that can be `throw`-n.
1954 + *
1955 + * @param {State} state Data state.
1956 + * @param {string} selectorName Selector name.
1957 + * @param {unknown[]?} args Arguments passed to selector.
1958 + *
1959 + * @return {Error|unknown} Last resolution error
1960 + */
1961 +
1962 +function getResolutionError(state, selectorName, args) {
1963 + const resolutionState = getResolutionState(state, selectorName, args);
1964 + return (resolutionState === null || resolutionState === void 0 ? void 0 : resolutionState.status) === 'error' ? resolutionState.error : null;
1965 +}
1966 +/**
1818 1967 * Returns true if resolution has been triggered but has not yet completed for
1819 1968 * a given selector name, and arguments set.
1820 1969 *
1821 - * @param {State} state Data state.
1822 - * @param {string} selectorName Selector name.
1823 - * @param {unknown[]} [args] Arguments passed to selector.
1970 + * @param {State} state Data state.
1971 + * @param {string} selectorName Selector name.
1972 + * @param {unknown[]?} args Arguments passed to selector.
1824 1973 *
1825 1974 * @return {boolean} Whether resolution is in progress.
1826 1975 */
1827 1976
1828 -function isResolving(state, selectorName) {
1829 - let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1830 - return getIsResolving(state, selectorName, args) === true;
1977 +function isResolving(state, selectorName, args) {
1978 + var _getResolutionState3;
1979 +
1980 + return ((_getResolutionState3 = getResolutionState(state, selectorName, args)) === null || _getResolutionState3 === void 0 ? void 0 : _getResolutionState3.status) === 'resolving';
1831 1981 }
1832 1982 /**
1833 1983 * Returns the list of the cached resolvers.
1834 1984 *
@@ -1839,9 +1989,9 @@
1839 1989
1840 1990 function getCachedResolvers(state) {
1841 1991 return state;
1842 1992 }
1843 -//# sourceMappingURL=selectors.js.map
1993 +
1844 1994 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/actions.js
1845 1995 /**
1846 1996 * Returns an action object used in signalling that selector resolution has
1847 1997 * started.
@@ -1875,16 +2025,35 @@
1875 2025 args
1876 2026 };
1877 2027 }
1878 2028 /**
2029 + * Returns an action object used in signalling that selector resolution has
2030 + * failed.
2031 + *
2032 + * @param {string} selectorName Name of selector for which resolver triggered.
2033 + * @param {unknown[]} args Arguments to associate for uniqueness.
2034 + * @param {Error|unknown} error The error that caused the failure.
2035 + *
2036 + * @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.
2037 + */
2038 +
2039 +function failResolution(selectorName, args, error) {
2040 + return {
2041 + type: 'FAIL_RESOLUTION',
2042 + selectorName,
2043 + args,
2044 + error
2045 + };
2046 +}
2047 +/**
1879 2048 * Returns an action object used in signalling that a batch of selector resolutions has
1880 2049 * started.
1881 2050 *
1882 - * @param {string} selectorName Name of selector for which resolver triggered.
1883 - * @param {unknown[]} args Array of arguments to associate for uniqueness, each item
1884 - * is associated to a resolution.
2051 + * @param {string} selectorName Name of selector for which resolver triggered.
2052 + * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
2053 + * is associated to a resolution.
1885 2054 *
1886 - * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[] }} Action object.
2055 + * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
1887 2056 */
1888 2057
1889 2058 function startResolutions(selectorName, args) {
1890 2059 return {
@@ -1896,13 +2065,13 @@
1896 2065 /**
1897 2066 * Returns an action object used in signalling that a batch of selector resolutions has
1898 2067 * completed.
1899 2068 *
1900 - * @param {string} selectorName Name of selector for which resolver triggered.
1901 - * @param {unknown[]} args Array of arguments to associate for uniqueness, each item
1902 - * is associated to a resolution.
2069 + * @param {string} selectorName Name of selector for which resolver triggered.
2070 + * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
2071 + * is associated to a resolution.
1903 2072 *
1904 - * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[] }} Action object.
2073 + * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
1905 2074 */
1906 2075
1907 2076 function finishResolutions(selectorName, args) {
1908 2077 return {
@@ -1911,8 +2080,28 @@
1911 2080 args
1912 2081 };
1913 2082 }
1914 2083 /**
2084 + * Returns an action object used in signalling that a batch of selector resolutions has
2085 + * completed and at least one of them has failed.
2086 + *
2087 + * @param {string} selectorName Name of selector for which resolver triggered.
2088 + * @param {unknown[]} args Array of arguments to associate for uniqueness, each item
2089 + * is associated to a resolution.
2090 + * @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item
2091 + * is associated to a resolution.
2092 + * @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.
2093 + */
2094 +
2095 +function failResolutions(selectorName, args, errors) {
2096 + return {
2097 + type: 'FAIL_RESOLUTIONS',
2098 + selectorName,
2099 + args,
2100 + errors
2101 + };
2102 +}
2103 +/**
1915 2104 * Returns an action object used in signalling that we should invalidate the resolution cache.
1916 2105 *
1917 2106 * @param {string} selectorName Name of selector for which resolver should be invalidated.
1918 2107 * @param {unknown[]} args Arguments to associate for uniqueness.
@@ -1954,9 +2143,9 @@
1954 2143 type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR',
1955 2144 selectorName
1956 2145 };
1957 2146 }
1958 -//# sourceMappingURL=actions.js.map
2147 +
1959 2148 ;// CONCATENATED MODULE: ./packages/data/build-module/redux-store/index.js
1960 2149 /**
1961 2150 * External dependencies
1962 2151 */
@@ -1968,8 +2157,9 @@
1968 2157 * WordPress dependencies
1969 2158 */
1970 2159
1971 2160
2161 +
1972 2162 /**
1973 2163 * Internal dependencies
1974 2164 */
1975 2165
@@ -1981,11 +2171,17 @@
1981 2171
1982 2172
1983 2173 /** @typedef {import('../types').DataRegistry} DataRegistry */
1984 2174
1985 -/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */
2175 +/**
2176 + * @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor
2177 + * @template C
2178 + */
1986 2179
1987 -/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */
2180 +/**
2181 + * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
2182 + * @template State,Actions,Selectors
2183 + */
1988 2184
1989 2185 const trimUndefinedValues = array => {
1990 2186 const result = [...array];
1991 2187
@@ -2042,14 +2238,15 @@
2042 2238 * },
2043 2239 * } );
2044 2240 * ```
2045 2241 *
2046 - * @param {string} key Unique namespace identifier.
2047 - * @param {ReduxStoreConfig} options Registered store options, with properties
2048 - * describing reducer, actions, selectors,
2049 - * and resolvers.
2242 + * @template State,Actions,Selectors
2243 + * @param {string} key Unique namespace identifier.
2244 + * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties
2245 + * describing reducer, actions, selectors,
2246 + * and resolvers.
2050 2247 *
2051 - * @return {StoreDescriptor} Store Object.
2248 + * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object.
2052 2249 */
2053 2250
2054 2251
2055 2252 function createReduxStore(key, options) {
@@ -2107,14 +2304,17 @@
2107 2304 selectors = result.selectors;
2108 2305 }
2109 2306
2110 2307 const resolveSelectors = mapResolveSelectors(selectors, store);
2308 + const suspendSelectors = mapSuspendSelectors(selectors, store);
2111 2309
2112 2310 const getSelectors = () => selectors;
2113 2311
2114 2312 const getActions = () => actions;
2115 2313
2116 - const getResolveSelectors = () => resolveSelectors; // We have some modules monkey-patching the store object
2314 + const getResolveSelectors = () => resolveSelectors;
2315 +
2316 + const getSuspendSelectors = () => suspendSelectors; // We have some modules monkey-patching the store object
2117 2317 // It's wrong to do so but until we refactor all of our effects to controls
2118 2318 // We need to keep the same "store" instance here.
2119 2319
2120 2320
@@ -2148,8 +2348,9 @@
2148 2348 selectors,
2149 2349 resolvers,
2150 2350 getSelectors,
2151 2351 getResolveSelectors,
2352 + getSuspendSelectors,
2152 2353 getActions,
2153 2354 subscribe
2154 2355 };
2155 2356 }
@@ -2171,14 +2372,9 @@
2171 2372 const controls = { ...options.controls,
2172 2373 ...builtinControls
2173 2374 };
2174 2375 const normalizedControls = (0,external_lodash_namespaceObject.mapValues)(controls, control => control.isRegistryControl ? control(registry) : control);
2175 - const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls)];
2176 -
2177 - if (options.__experimentalUseThunks) {
2178 - middlewares.push(createThunkMiddleware(thunkArgs));
2179 - }
2180 -
2376 + const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls), createThunkMiddleware(thunkArgs)];
2181 2377 const enhancers = [applyMiddleware(...middlewares)];
2182 2378
2183 2379 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
2184 2380 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({
@@ -2196,9 +2392,9 @@
2196 2392 root: reducer
2197 2393 });
2198 2394 return createStore(enhancedReducer, {
2199 2395 root: initialState
2200 - }, (0,external_lodash_namespaceObject.flowRight)(enhancers));
2396 + }, (0,external_wp_compose_namespaceObject.compose)(enhancers));
2201 2397 }
2202 2398 /**
2203 2399 * Maps selectors to a store.
2204 2400 *
@@ -2264,32 +2460,111 @@
2264 2460 */
2265 2461
2266 2462
2267 2463 function mapResolveSelectors(selectors, store) {
2268 - return (0,external_lodash_namespaceObject.mapValues)((0,external_lodash_namespaceObject.omit)(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']), (selector, selectorName) => function () {
2269 - for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2270 - args[_key3] = arguments[_key3];
2464 + const {
2465 + getIsResolving,
2466 + hasStartedResolution,
2467 + hasFinishedResolution,
2468 + hasResolutionFailed,
2469 + isResolving,
2470 + getCachedResolvers,
2471 + getResolutionState,
2472 + getResolutionError,
2473 + ...storeSelectors
2474 + } = selectors;
2475 + return (0,external_lodash_namespaceObject.mapValues)(storeSelectors, (selector, selectorName) => {
2476 + // If the selector doesn't have a resolver, just convert the return value
2477 + // (including exceptions) to a Promise, no additional extra behavior is needed.
2478 + if (!selector.hasResolver) {
2479 + return async function () {
2480 + for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2481 + args[_key3] = arguments[_key3];
2482 + }
2483 +
2484 + return selector.apply(null, args);
2485 + };
2271 2486 }
2272 2487
2273 - return new Promise(resolve => {
2274 - const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
2488 + return function () {
2489 + for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2490 + args[_key4] = arguments[_key4];
2491 + }
2275 2492
2276 - const getResult = () => selector.apply(null, args); // trigger the selector (to trigger the resolver)
2493 + return new Promise((resolve, reject) => {
2494 + const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
2277 2495
2496 + const finalize = result => {
2497 + const hasFailed = selectors.hasResolutionFailed(selectorName, args);
2278 2498
2279 - const result = getResult();
2499 + if (hasFailed) {
2500 + const error = selectors.getResolutionError(selectorName, args);
2501 + reject(error);
2502 + } else {
2503 + resolve(result);
2504 + }
2505 + };
2280 2506
2281 - if (hasFinished()) {
2282 - return resolve(result);
2507 + const getResult = () => selector.apply(null, args); // Trigger the selector (to trigger the resolver)
2508 +
2509 +
2510 + const result = getResult();
2511 +
2512 + if (hasFinished()) {
2513 + return finalize(result);
2514 + }
2515 +
2516 + const unsubscribe = store.subscribe(() => {
2517 + if (hasFinished()) {
2518 + unsubscribe();
2519 + finalize(getResult());
2520 + }
2521 + });
2522 + });
2523 + };
2524 + });
2525 +}
2526 +/**
2527 + * Maps selectors to functions that throw a suspense promise if not yet resolved.
2528 + *
2529 + * @param {Object} selectors Selectors to map.
2530 + * @param {Object} store The redux store the selectors select from.
2531 + *
2532 + * @return {Object} Selectors mapped to their suspense functions.
2533 + */
2534 +
2535 +
2536 +function mapSuspendSelectors(selectors, store) {
2537 + return (0,external_lodash_namespaceObject.mapValues)(selectors, (selector, selectorName) => {
2538 + // Selector without a resolver doesn't have any extra suspense behavior.
2539 + if (!selector.hasResolver) {
2540 + return selector;
2541 + }
2542 +
2543 + return function () {
2544 + for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2545 + args[_key5] = arguments[_key5];
2283 2546 }
2284 2547
2285 - const unsubscribe = store.subscribe(() => {
2286 - if (hasFinished()) {
2287 - unsubscribe();
2288 - resolve(getResult());
2548 + const result = selector.apply(null, args);
2549 +
2550 + if (selectors.hasFinishedResolution(selectorName, args)) {
2551 + if (selectors.hasResolutionFailed(selectorName, args)) {
2552 + throw selectors.getResolutionError(selectorName, args);
2289 2553 }
2554 +
2555 + return result;
2556 + }
2557 +
2558 + throw new Promise(resolve => {
2559 + const unsubscribe = store.subscribe(() => {
2560 + if (selectors.hasFinishedResolution(selectorName, args)) {
2561 + resolve();
2562 + unsubscribe();
2563 + }
2564 + });
2290 2565 });
2291 - });
2566 + };
2292 2567 });
2293 2568 }
2294 2569 /**
2295 2570 * Returns resolvers with matched selectors for a given namespace.
@@ -2312,10 +2587,10 @@
2312 2587 return resolver;
2313 2588 }
2314 2589
2315 2590 return { ...resolver,
2316 - // copy the enumerable properties of the resolver function
2317 - fulfill: resolver // add the fulfill method
2591 + // Copy the enumerable properties of the resolver function.
2592 + fulfill: resolver // Add the fulfill method.
2318 2593
2319 2594 };
2320 2595 });
2321 2596
@@ -2327,10 +2602,10 @@
2327 2602 return selector;
2328 2603 }
2329 2604
2330 2605 const selectorResolver = function () {
2331 - for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2332 - args[_key4] = arguments[_key4];
2606 + for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
2607 + args[_key6] = arguments[_key6];
2333 2608 }
2334 2609
2335 2610 async function fulfillSelector() {
2336 2611 const state = store.getState();
@@ -2350,10 +2625,15 @@
2350 2625 resolversCache.markAsRunning(selectorName, args);
2351 2626 setTimeout(async () => {
2352 2627 resolversCache.clear(selectorName, args);
2353 2628 store.dispatch(startResolution(selectorName, args));
2354 - await fulfillResolver(store, mappedResolvers, selectorName, ...args);
2355 - store.dispatch(finishResolution(selectorName, args));
2629 +
2630 + try {
2631 + await fulfillResolver(store, mappedResolvers, selectorName, ...args);
2632 + store.dispatch(finishResolution(selectorName, args));
2633 + } catch (error) {
2634 + store.dispatch(failResolution(selectorName, args, error));
2635 + }
2356 2636 });
2357 2637 }
2358 2638
2359 2639 fulfillSelector(...args);
@@ -2385,10 +2665,10 @@
2385 2665 if (!resolver) {
2386 2666 return;
2387 2667 }
2388 2668
2389 - for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
2390 - args[_key5 - 3] = arguments[_key5];
2669 + for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key7 = 3; _key7 < _len7; _key7++) {
2670 + args[_key7 - 3] = arguments[_key7];
2391 2671 }
2392 2672
2393 2673 const action = resolver.fulfill(...args);
2394 2674
@@ -2395,9 +2675,9 @@
2395 2675 if (action) {
2396 2676 await store.dispatch(action);
2397 2677 }
2398 2678 }
2399 -//# sourceMappingURL=index.js.map
2679 +
2400 2680 ;// CONCATENATED MODULE: ./packages/data/build-module/utils/emitter.js
2401 2681 /**
2402 2682 * Create an event emitter.
2403 2683 *
@@ -2446,9 +2726,9 @@
2446 2726 }
2447 2727
2448 2728 };
2449 2729 }
2450 -//# sourceMappingURL=emitter.js.map
2730 +
2451 2731 ;// CONCATENATED MODULE: ./packages/data/build-module/registry.js
2452 2732 /**
2453 2733 * External dependencies
2454 2734 */
@@ -2492,8 +2772,11 @@
2492 2772 *
2493 2773 * @property {Function} registerStore registers store.
2494 2774 */
2495 2775
2776 +function registry_isObject(object) {
2777 + return object !== null && typeof object === 'object';
2778 +}
2496 2779 /**
2497 2780 * Creates a new store registry, given an optional object of initial store
2498 2781 * configurations.
2499 2782 *
@@ -2502,20 +2785,19 @@
2502 2785 *
2503 2786 * @return {WPDataRegistry} Data registry.
2504 2787 */
2505 2788
2789 +
2506 2790 function createRegistry() {
2507 2791 let storeConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2508 2792 let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2509 2793 const stores = {};
2510 2794 const emitter = createEmitter();
2511 -
2512 - const __experimentalListeningStores = new Set();
2795 + const listeningStores = new Set();
2513 2796 /**
2514 2797 * Global listener called for each store's update.
2515 2798 */
2516 2799
2517 -
2518 2800 function globalListener() {
2519 2801 emitter.emit();
2520 2802 }
2521 2803 /**
@@ -2540,12 +2822,10 @@
2540 2822 */
2541 2823
2542 2824
2543 2825 function select(storeNameOrDescriptor) {
2544 - const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2545 -
2546 - __experimentalListeningStores.add(storeName);
2547 -
2826 + const storeName = registry_isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2827 + listeningStores.add(storeName);
2548 2828 const store = stores[storeName];
2549 2829
2550 2830 if (store) {
2551 2831 return store.getSelectors();
@@ -2550,26 +2830,28 @@
2550 2830 if (store) {
2551 2831 return store.getSelectors();
2552 2832 }
2553 2833
2554 - return parent && parent.select(storeName);
2834 + return parent === null || parent === void 0 ? void 0 : parent.select(storeName);
2555 2835 }
2556 2836
2557 - function __experimentalMarkListeningStores(callback, ref) {
2558 - __experimentalListeningStores.clear();
2837 + function __unstableMarkListeningStores(callback, ref) {
2838 + listeningStores.clear();
2559 2839
2560 - const result = callback.call(this);
2561 - ref.current = Array.from(__experimentalListeningStores);
2562 - return result;
2840 + try {
2841 + return callback.call(this);
2842 + } finally {
2843 + ref.current = Array.from(listeningStores);
2844 + }
2563 2845 }
2564 2846 /**
2565 - * Given the name of a registered store, returns an object containing the store's
2566 - * selectors pre-bound to state so that you only need to supply additional arguments,
2567 - * and modified so that they return promises that resolve to their eventual values,
2568 - * after any resolvers have ran.
2847 + * Given a store descriptor, returns an object containing the store's selectors pre-bound to
2848 + * state so that you only need to supply additional arguments, and modified so that they return
2849 + * promises that resolve to their eventual values, after any resolvers have ran.
2569 2850 *
2570 - * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
2571 - * or the store descriptor.
2851 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
2852 + * convention of passing the store name is
2853 + * also supported.
2572 2854 *
2573 2855 * @return {Object} Each key of the object matches the name of a selector.
2574 2856 */
2575 2857
@@ -2574,19 +2856,41 @@
2574 2856 */
2575 2857
2576 2858
2577 2859 function resolveSelect(storeNameOrDescriptor) {
2578 - const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2860 + const storeName = registry_isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2861 + listeningStores.add(storeName);
2862 + const store = stores[storeName];
2579 2863
2580 - __experimentalListeningStores.add(storeName);
2864 + if (store) {
2865 + return store.getResolveSelectors();
2866 + }
2581 2867
2868 + return parent && parent.resolveSelect(storeName);
2869 + }
2870 + /**
2871 + * Given a store descriptor, returns an object containing the store's selectors pre-bound to
2872 + * state so that you only need to supply additional arguments, and modified so that they throw
2873 + * promises in case the selector is not resolved yet.
2874 + *
2875 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
2876 + * convention of passing the store name is
2877 + * also supported.
2878 + *
2879 + * @return {Object} Object containing the store's suspense-wrapped selectors.
2880 + */
2881 +
2882 +
2883 + function suspendSelect(storeNameOrDescriptor) {
2884 + const storeName = registry_isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2885 + listeningStores.add(storeName);
2582 2886 const store = stores[storeName];
2583 2887
2584 2888 if (store) {
2585 - return store.getResolveSelectors();
2889 + return store.getSuspendSelectors();
2586 2890 }
2587 2891
2588 - return parent && parent.resolveSelect(storeName);
2892 + return parent && parent.suspendSelect(storeName);
2589 2893 }
2590 2894 /**
2591 2895 * Returns the available actions for a part of the state.
2592 2896 *
@@ -2597,9 +2901,9 @@
2597 2901 */
2598 2902
2599 2903
2600 2904 function dispatch(storeNameOrDescriptor) {
2601 - const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2905 + const storeName = registry_isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
2602 2906 const store = stores[storeName];
2603 2907
2604 2908 if (store) {
2605 2909 return store.getActions();
@@ -2608,9 +2912,8 @@
2608 2912 return parent && parent.dispatch(storeName);
2609 2913 } //
2610 2914 // Deprecated
2611 2915 // TODO: Remove this after `use()` is removed.
2612 - //
2613 2916
2614 2917
2615 2918 function withPlugins(attributes) {
2616 2919 return (0,external_lodash_namespaceObject.mapValues)(attributes, (attribute, key) => {
@@ -2714,9 +3017,9 @@
2714 3017 * @return {Function} A function to unsubscribe the handler.
2715 3018 */
2716 3019
2717 3020
2718 - function __experimentalSubscribeStore(storeName, handler) {
3021 + function __unstableSubscribeStore(storeName, handler) {
2719 3022 if (storeName in stores) {
2720 3023 return stores[storeName].subscribe(handler);
2721 3024 } // Trying to access a store that hasn't been registered,
2722 3025 // this is a pattern rarely used but seen in some places.
@@ -2727,17 +3030,17 @@
2727 3030 if (!parent) {
2728 3031 return subscribe(handler);
2729 3032 }
2730 3033
2731 - return parent.__experimentalSubscribeStore(storeName, handler);
3034 + return parent.__unstableSubscribeStore(storeName, handler);
2732 3035 }
2733 3036
2734 3037 function batch(callback) {
2735 3038 emitter.pause();
2736 - (0,external_lodash_namespaceObject.forEach)(stores, store => store.emitter.pause());
3039 + Object.values(stores).forEach(store => store.emitter.pause());
2737 3040 callback();
2738 3041 emitter.resume();
2739 - (0,external_lodash_namespaceObject.forEach)(stores, store => store.emitter.resume());
3042 + Object.values(stores).forEach(store => store.emitter.resume());
2740 3043 }
2741 3044
2742 3045 let registry = {
2743 3046 batch,
@@ -2746,19 +3049,19 @@
2746 3049 // TODO: Deprecate/remove this.
2747 3050 subscribe,
2748 3051 select,
2749 3052 resolveSelect,
3053 + suspendSelect,
2750 3054 dispatch,
2751 3055 use,
2752 3056 register,
2753 3057 registerGenericStore,
2754 3058 registerStore,
2755 - __experimentalMarkListeningStores,
2756 - __experimentalSubscribeStore
3059 + __unstableMarkListeningStores,
3060 + __unstableSubscribeStore
2757 3061 }; //
2758 3062 // TODO:
2759 3063 // This function will be deprecated as soon as it is no longer internally referenced.
2760 - //
2761 3064
2762 3065 function use(plugin, options) {
2763 3066 if (!plugin) {
2764 3067 return;
@@ -2781,16 +3084,52 @@
2781 3084 }
2782 3085
2783 3086 return withPlugins(registry);
2784 3087 }
2785 -//# sourceMappingURL=registry.js.map
3088 +
2786 3089 ;// CONCATENATED MODULE: ./packages/data/build-module/default-registry.js
2787 3090 /**
2788 3091 * Internal dependencies
2789 3092 */
2790 3093
2791 -/* harmony default export */ var default_registry = (createRegistry());
2792 -//# sourceMappingURL=default-registry.js.map
3094 +/* harmony default export */ const default_registry = (createRegistry());
3095 +
3096 +;// CONCATENATED MODULE: ./node_modules/is-plain-object/dist/is-plain-object.mjs
3097 +/*!
3098 + * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
3099 + *
3100 + * Copyright (c) 2014-2017, Jon Schlinkert.
3101 + * Released under the MIT License.
3102 + */
3103 +
3104 +function is_plain_object_isObject(o) {
3105 + return Object.prototype.toString.call(o) === '[object Object]';
3106 +}
3107 +
3108 +function is_plain_object_isPlainObject(o) {
3109 + var ctor,prot;
3110 +
3111 + if (is_plain_object_isObject(o) === false) return false;
3112 +
3113 + // If has modified constructor
3114 + ctor = o.constructor;
3115 + if (ctor === undefined) return true;
3116 +
3117 + // If has modified prototype
3118 + prot = ctor.prototype;
3119 + if (is_plain_object_isObject(prot) === false) return false;
3120 +
3121 + // If constructor does not have an Object-specific method
3122 + if (prot.hasOwnProperty('isPrototypeOf') === false) {
3123 + return false;
3124 + }
3125 +
3126 + // Most likely a plain Object
3127 + return true;
3128 +}
3129 +
3130 +
3131 +
2793 3132 ;// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/storage/object.js
2794 3133 let objectStorage;
2795 3134 const storage = {
2796 3135 getItem(key) {
@@ -2813,10 +3152,10 @@
2813 3152 objectStorage = Object.create(null);
2814 3153 }
2815 3154
2816 3155 };
2817 -/* harmony default export */ var object = (storage);
2818 -//# sourceMappingURL=object.js.map
3156 +/* harmony default export */ const object = (storage);
3157 +
2819 3158 ;// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/storage/default.js
2820 3159 /**
2821 3160 * Internal dependencies
2822 3161 */
@@ -2833,15 +3172,16 @@
2833 3172 } catch (error) {
2834 3173 default_storage = object;
2835 3174 }
2836 3175
2837 -/* harmony default export */ var storage_default = (default_storage);
2838 -//# sourceMappingURL=default.js.map
3176 +/* harmony default export */ const storage_default = (default_storage);
3177 +
2839 3178 ;// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/index.js
2840 3179 /**
2841 3180 * External dependencies
2842 3181 */
2843 3182
3183 +
2844 3184 /**
2845 3185 * Internal dependencies
2846 3186 */
2847 3187
@@ -2987,9 +3327,9 @@
2987 3327 // equality to bypass a persistence set on an unchanging state.
2988 3328 const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, {
2989 3329 [key]: (state, action) => action.nextState[key]
2990 3330 }), {});
2991 - getPersistedState = withLazySameState(turbo_combine_reducers_default()(reducers));
3331 + getPersistedState = withLazySameState(build_module_combineReducers(reducers));
2992 3332 } else {
2993 3333 getPersistedState = (state, action) => action.nextState;
2994 3334 }
2995 3335
@@ -3021,9 +3361,9 @@
3021 3361 let initialState = options.reducer(options.initialState, {
3022 3362 type: '@@WP/PERSISTENCE_RESTORE'
3023 3363 });
3024 3364
3025 - if ((0,external_lodash_namespaceObject.isPlainObject)(initialState) && (0,external_lodash_namespaceObject.isPlainObject)(persistedState)) {
3365 + if (is_plain_object_isPlainObject(initialState) && is_plain_object_isPlainObject(persistedState)) {
3026 3366 // If state is an object, ensure that:
3027 3367 // - Other keys are left intact when persisting only a
3028 3368 // subset of keys.
3029 3369 // - New keys in what would otherwise be used as initial
@@ -3046,69 +3386,16 @@
3046 3386 }
3047 3387
3048 3388 };
3049 3389 }
3050 -/**
3051 - * Move the 'features' object in local storage from the sourceStoreName to the
3052 - * interface store.
3053 - *
3054 - * @param {Object} persistence The persistence interface.
3055 - * @param {string} sourceStoreName The name of the store that has persisted
3056 - * preferences to migrate to the interface
3057 - * package.
3058 - */
3059 3390
3391 +persistencePlugin.__unstableMigrate = () => {};
3060 3392
3061 -function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName) {
3062 - var _state$sourceStoreNam;
3393 +/* harmony default export */ const persistence = (persistencePlugin);
3063 3394
3064 - const interfaceStoreName = 'core/interface';
3065 - const state = persistence.get();
3066 - const sourcePreferences = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : _state$sourceStoreNam.preferences;
3067 - const sourceFeatures = sourcePreferences === null || sourcePreferences === void 0 ? void 0 : sourcePreferences.features;
3395 +;// CONCATENATED MODULE: ./packages/data/build-module/plugins/index.js
3068 3396
3069 - if (sourceFeatures) {
3070 - var _state$interfaceStore, _state$interfaceStore2;
3071 3397
3072 - const targetFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : _state$interfaceStore2.features; // Avoid migrating features again if they've previously been migrated.
3073 -
3074 - if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
3075 - // Set the feature values in the interface store, the features
3076 - // object is keyed by 'scope', which matches the store name for
3077 - // the source.
3078 - persistence.set(interfaceStoreName, {
3079 - preferences: {
3080 - features: { ...targetFeatures,
3081 - [sourceStoreName]: sourceFeatures
3082 - }
3083 - }
3084 - }); // Remove feature preferences from the source.
3085 -
3086 - persistence.set(sourceStoreName, {
3087 - preferences: { ...sourcePreferences,
3088 - features: undefined
3089 - }
3090 - });
3091 - }
3092 - }
3093 -}
3094 -/**
3095 - * Deprecated: Remove this function and the code in WordPress Core that calls
3096 - * it once WordPress 6.0 is released.
3097 - */
3098 -
3099 -persistencePlugin.__unstableMigrate = pluginOptions => {
3100 - const persistence = createPersistenceInterface(pluginOptions);
3101 - migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-widgets');
3102 - migrateFeaturePreferencesToInterfaceStore(persistence, 'core/customize-widgets');
3103 - migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-post');
3104 -};
3105 -
3106 -/* harmony default export */ var persistence = (persistencePlugin);
3107 -//# sourceMappingURL=index.js.map
3108 -;// CONCATENATED MODULE: ./packages/data/build-module/plugins/index.js
3109 -
3110 -//# sourceMappingURL=index.js.map
3111 3398 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
3112 3399 function _extends() {
3113 3400 _extends = Object.assign || function (target) {
3114 3401 for (var i = 1; i < arguments.length; i++) {
@@ -3126,13 +3413,11 @@
3126 3413
3127 3414 return _extends.apply(this, arguments);
3128 3415 }
3129 3416 ;// CONCATENATED MODULE: external ["wp","element"]
3130 -var external_wp_element_namespaceObject = window["wp"]["element"];
3131 -;// CONCATENATED MODULE: external ["wp","compose"]
3132 -var external_wp_compose_namespaceObject = window["wp"]["compose"];
3417 +const external_wp_element_namespaceObject = window["wp"]["element"];
3133 3418 ;// CONCATENATED MODULE: external "React"
3134 -var external_React_namespaceObject = window["React"];
3419 +const external_React_namespaceObject = window["React"];
3135 3420 ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js
3136 3421
3137 3422
3138 3423 function areInputsEqual(newInputs, lastInputs) {
@@ -3177,11 +3462,11 @@
3177 3462
3178 3463
3179 3464
3180 3465 ;// CONCATENATED MODULE: external ["wp","priorityQueue"]
3181 -var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"];
3466 +const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"];
3182 3467 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
3183 -var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
3468 +const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
3184 3469 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
3185 3470 ;// CONCATENATED MODULE: ./packages/data/build-module/components/registry-provider/context.js
3186 3471 /**
3187 3472 * WordPress dependencies
@@ -3237,10 +3522,10 @@
3237 3522 * See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for
3238 3523 * example.
3239 3524 */
3240 3525
3241 -/* harmony default export */ var context = (Provider);
3242 -//# sourceMappingURL=context.js.map
3526 +/* harmony default export */ const context = (Provider);
3527 +
3243 3528 ;// CONCATENATED MODULE: ./packages/data/build-module/components/registry-provider/use-registry.js
3244 3529 /**
3245 3530 * WordPress dependencies
3246 3531 */
@@ -3292,9 +3577,9 @@
3292 3577
3293 3578 function useRegistry() {
3294 3579 return (0,external_wp_element_namespaceObject.useContext)(Context);
3295 3580 }
3296 -//# sourceMappingURL=use-registry.js.map
3581 +
3297 3582 ;// CONCATENATED MODULE: ./packages/data/build-module/components/async-mode-provider/context.js
3298 3583 /**
3299 3584 * WordPress dependencies
3300 3585 */
@@ -3312,12 +3597,13 @@
3312 3597 * @example
3313 3598 *
3314 3599 * ```js
3315 3600 * import { useSelect, AsyncModeProvider } from '@wordpress/data';
3601 + * import { store as blockEditorStore } from '@wordpress/block-editor';
3316 3602 *
3317 3603 * function BlockCount() {
3318 3604 * const count = useSelect( ( select ) => {
3319 - * return select( 'core/block-editor' ).getBlockCount()
3605 + * return select( blockEditorStore ).getBlockCount()
3320 3606 * }, [] );
3321 3607 *
3322 3608 * return count;
3323 3609 * }
@@ -3339,10 +3625,10 @@
3339 3625 * @param {boolean} props.value Enable Async Mode.
3340 3626 * @return {WPComponent} The component to be rendered.
3341 3627 */
3342 3628
3343 -/* harmony default export */ var async_mode_provider_context = (context_Provider);
3344 -//# sourceMappingURL=context.js.map
3629 +/* harmony default export */ const async_mode_provider_context = (context_Provider);
3630 +
3345 3631 ;// CONCATENATED MODULE: ./packages/data/build-module/components/async-mode-provider/use-async-mode.js
3346 3632 /**
3347 3633 * WordPress dependencies
3348 3634 */
@@ -3354,9 +3640,9 @@
3354 3640
3355 3641 function useAsyncMode() {
3356 3642 return (0,external_wp_element_namespaceObject.useContext)(context_Context);
3357 3643 }
3358 -//# sourceMappingURL=use-async-mode.js.map
3644 +
3359 3645 ;// CONCATENATED MODULE: ./packages/data/build-module/components/use-select/index.js
3360 3646 /**
3361 3647 * External dependencies
3362 3648 */
@@ -3378,38 +3664,50 @@
3378 3664
3379 3665 const noop = () => {};
3380 3666
3381 3667 const renderQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)();
3382 -/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */
3668 +/**
3669 + * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
3670 + * @template C
3671 + */
3383 3672
3384 3673 /**
3674 + * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
3675 + * @template State,Actions,Selectors
3676 + */
3677 +
3678 +/**
3679 + * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
3680 + * @template T
3681 + */
3682 +
3683 +/** @typedef {import('../../types').MapSelect} MapSelect */
3684 +
3685 +/**
3385 3686 * Custom react hook for retrieving props from registered selectors.
3386 3687 *
3387 3688 * In general, this custom React hook follows the
3388 3689 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).
3389 3690 *
3390 - * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The
3391 - * returned value is exposed to the component
3392 - * implementing this hook. The function receives
3393 - * the `registry.select` method on the first
3394 - * argument and the `registry` on the second
3395 - * argument.
3396 - * When a store key is passed, all selectors for
3397 - * the store will be returned. This is only meant
3398 - * for usage of these selectors in event
3399 - * callbacks, not for data needed to create the
3400 - * element tree.
3401 - * @param {Array} deps If provided, this memoizes the mapSelect so the
3402 - * same `mapSelect` is invoked on every state
3403 - * change unless the dependencies change.
3691 + * @template {MapSelect | StoreDescriptor<any>} T
3692 + * @param {T} mapSelect Function called on every state change. The returned value is
3693 + * exposed to the component implementing this hook. The function
3694 + * receives the `registry.select` method on the first argument
3695 + * and the `registry` on the second argument.
3696 + * When a store key is passed, all selectors for the store will be
3697 + * returned. This is only meant for usage of these selectors in event
3698 + * callbacks, not for data needed to create the element tree.
3699 + * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is
3700 + * invoked on every state change unless the dependencies change.
3404 3701 *
3405 3702 * @example
3406 3703 * ```js
3407 3704 * import { useSelect } from '@wordpress/data';
3705 + * import { store as myCustomStore } from 'my-custom-store';
3408 3706 *
3409 3707 * function HammerPriceDisplay( { currency } ) {
3410 3708 * const price = useSelect( ( select ) => {
3411 - * return select( 'my-shop' ).getPrice( 'hammer', currency )
3709 + * return select( myCustomStore ).getPrice( 'hammer', currency );
3412 3710 * }, [ currency ] );
3413 3711 * return new Intl.NumberFormat( 'en-US', {
3414 3712 * style: 'currency',
3415 3713 * currency,
@@ -3434,11 +3732,12 @@
3434 3732 * function because your component won't re-render on a data change.**
3435 3733 *
3436 3734 * ```js
3437 3735 * import { useSelect } from '@wordpress/data';
3736 + * import { store as myCustomStore } from 'my-custom-store';
3438 3737 *
3439 3738 * function Paste( { children } ) {
3440 - * const { getSettings } = useSelect( 'my-shop' );
3739 + * const { getSettings } = useSelect( myCustomStore );
3441 3740 * function onPaste() {
3442 3741 * // Do something with the settings.
3443 3742 * const settings = getSettings();
3444 3743 * }
@@ -3444,10 +3743,9 @@
3444 3743 * }
3445 3744 * return <div onPaste={ onPaste }>{ children }</div>;
3446 3745 * }
3447 3746 * ```
3448 - *
3449 - * @return {Function} A custom react hook.
3747 + * @return {UseSelectReturn<T>} A custom react hook.
3450 3748 */
3451 3749
3452 3750 function useSelect(mapSelect, deps) {
3453 3751 const hasMappingFunction = 'function' === typeof mapSelect; // If we're recalling a store by its name or by
@@ -3467,39 +3765,36 @@
3467 3765
3468 3766 const _mapSelect = hasMappingFunction ? callbackMapper : null;
3469 3767
3470 3768 const registry = useRegistry();
3471 - const isAsync = useAsyncMode(); // React can sometimes clear the `useMemo` cache.
3472 - // We use the cache-stable `useMemoOne` to avoid
3473 - // losing queues.
3474 -
3475 - const queueContext = useMemoOne(() => ({
3476 - queue: true
3477 - }), [registry]);
3478 - const [, forceRender] = (0,external_wp_element_namespaceObject.useReducer)(s => s + 1, 0);
3769 + const isAsync = useAsyncMode();
3770 + const latestRegistry = (0,external_wp_element_namespaceObject.useRef)(registry);
3479 3771 const latestMapSelect = (0,external_wp_element_namespaceObject.useRef)();
3480 3772 const latestIsAsync = (0,external_wp_element_namespaceObject.useRef)(isAsync);
3481 3773 const latestMapOutput = (0,external_wp_element_namespaceObject.useRef)();
3482 - const latestMapOutputError = (0,external_wp_element_namespaceObject.useRef)();
3483 - const isMountedAndNotUnsubscribing = (0,external_wp_element_namespaceObject.useRef)(); // Keep track of the stores being selected in the _mapSelect function,
3774 + const latestMapOutputError = (0,external_wp_element_namespaceObject.useRef)(); // Keep track of the stores being selected in the _mapSelect function,
3484 3775 // and only subscribe to those stores later.
3485 3776
3486 3777 const listeningStores = (0,external_wp_element_namespaceObject.useRef)([]);
3487 - const trapSelect = (0,external_wp_element_namespaceObject.useCallback)(callback => registry.__experimentalMarkListeningStores(callback, listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
3778 + const wrapSelect = (0,external_wp_element_namespaceObject.useCallback)(callback => registry.__unstableMarkListeningStores(() => callback(registry.select, registry), listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
3488 3779 // It's different than just using `mapSelect` since deps could be undefined,
3489 3780 // in that case, we would still want to memoize it.
3490 3781
3491 3782 const depsChangedFlag = (0,external_wp_element_namespaceObject.useMemo)(() => ({}), deps || []);
3492 3783 let mapOutput;
3784 + let selectorRan = false;
3493 3785
3494 3786 if (_mapSelect) {
3495 3787 mapOutput = latestMapOutput.current;
3788 + const hasReplacedRegistry = latestRegistry.current !== registry;
3496 3789 const hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;
3790 + const hasLeftAsyncMode = latestIsAsync.current && !isAsync;
3497 3791 const lastMapSelectFailed = !!latestMapOutputError.current;
3498 3792
3499 - if (hasReplacedMapSelect || lastMapSelectFailed) {
3793 + if (hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode || lastMapSelectFailed) {
3500 3794 try {
3501 - mapOutput = trapSelect(() => _mapSelect(registry.select, registry));
3795 + mapOutput = wrapSelect(_mapSelect);
3796 + selectorRan = true;
3502 3797 } catch (error) {
3503 3798 let errorMessage = `An error occurred while running 'mapSelect': ${error.message}`;
3504 3799
3505 3800 if (latestMapOutputError.current) {
@@ -3518,21 +3813,26 @@
3518 3813 if (!hasMappingFunction) {
3519 3814 return;
3520 3815 }
3521 3816
3817 + latestRegistry.current = registry;
3522 3818 latestMapSelect.current = _mapSelect;
3523 - latestMapOutput.current = mapOutput;
3819 + latestIsAsync.current = isAsync;
3820 +
3821 + if (selectorRan) {
3822 + latestMapOutput.current = mapOutput;
3823 + }
3824 +
3524 3825 latestMapOutputError.current = undefined;
3525 - isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates
3526 - // to avoid using stale values in the flushed
3527 - // callbacks or potentially overwriting a
3528 - // changed `latestMapOutput.current`.
3826 + }); // React can sometimes clear the `useMemo` cache.
3827 + // We use the cache-stable `useMemoOne` to avoid
3828 + // losing queues.
3529 3829
3530 - if (latestIsAsync.current !== isAsync) {
3531 - latestIsAsync.current = isAsync;
3532 - renderQueue.flush(queueContext);
3533 - }
3534 - });
3830 + const queueContext = useMemoOne(() => ({
3831 + queue: true
3832 + }), [registry]);
3833 + const [, forceRender] = (0,external_wp_element_namespaceObject.useReducer)(s => s + 1, 0);
3834 + const isMounted = (0,external_wp_element_namespaceObject.useRef)(false);
3535 3835 (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => {
3536 3836 if (!hasMappingFunction) {
3537 3837 return;
3538 3838 }
@@ -3537,54 +3837,170 @@
3537 3837 return;
3538 3838 }
3539 3839
3540 3840 const onStoreChange = () => {
3541 - if (isMountedAndNotUnsubscribing.current) {
3542 - try {
3543 - const newMapOutput = trapSelect(() => latestMapSelect.current(registry.select, registry));
3841 + try {
3842 + const newMapOutput = wrapSelect(latestMapSelect.current);
3544 3843
3545 - if (external_wp_isShallowEqual_default()(latestMapOutput.current, newMapOutput)) {
3546 - return;
3547 - }
3548 -
3549 - latestMapOutput.current = newMapOutput;
3550 - } catch (error) {
3551 - latestMapOutputError.current = error;
3844 + if (external_wp_isShallowEqual_default()(latestMapOutput.current, newMapOutput)) {
3845 + return;
3552 3846 }
3553 3847
3554 - forceRender();
3848 + latestMapOutput.current = newMapOutput;
3849 + } catch (error) {
3850 + latestMapOutputError.current = error;
3555 3851 }
3556 - }; // catch any possible state changes during mount before the subscription
3557 - // could be set.
3558 3852
3853 + forceRender();
3854 + };
3559 3855
3560 - if (latestIsAsync.current) {
3561 - renderQueue.add(queueContext, onStoreChange);
3562 - } else {
3563 - onStoreChange();
3564 - }
3856 + const onChange = () => {
3857 + if (!isMounted.current) {
3858 + return;
3859 + }
3565 3860
3566 - const onChange = () => {
3567 3861 if (latestIsAsync.current) {
3568 3862 renderQueue.add(queueContext, onStoreChange);
3569 3863 } else {
3570 3864 onStoreChange();
3571 3865 }
3572 - };
3866 + }; // Catch any possible state changes during mount before the subscription
3867 + // could be set.
3573 3868
3574 - const unsubscribers = listeningStores.current.map(storeName => registry.__experimentalSubscribeStore(storeName, onChange));
3869 +
3870 + onStoreChange();
3871 + const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
3872 + isMounted.current = true;
3575 3873 return () => {
3576 - isMountedAndNotUnsubscribing.current = false; // The return value of the subscribe function could be undefined if the store is a custom generic store.
3577 -
3874 + // The return value of the subscribe function could be undefined if the store is a custom generic store.
3578 3875 unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
3579 - renderQueue.flush(queueContext);
3876 + renderQueue.cancel(queueContext);
3877 + isMounted.current = false;
3580 3878 }; // If you're tempted to eliminate the spread dependencies below don't do it!
3581 3879 // We're passing these in from the calling function and want to make sure we're
3582 3880 // examining every individual value inside the `deps` array.
3583 - }, [registry, trapSelect, hasMappingFunction, depsChangedFlag]);
3881 + }, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]);
3882 + (0,external_wp_element_namespaceObject.useDebugValue)(mapOutput);
3584 3883 return hasMappingFunction ? mapOutput : registry.select(mapSelect);
3585 3884 }
3586 -//# sourceMappingURL=index.js.map
3885 +/**
3886 + * A variant of the `useSelect` hook that has the same API, but will throw a
3887 + * suspense Promise if any of the called selectors is in an unresolved state.
3888 + *
3889 + * @param {Function} mapSelect Function called on every state change. The
3890 + * returned value is exposed to the component
3891 + * using this hook. The function receives the
3892 + * `registry.suspendSelect` method as the first
3893 + * argument and the `registry` as the second one.
3894 + * @param {Array} deps A dependency array used to memoize the `mapSelect`
3895 + * so that the same `mapSelect` is invoked on every
3896 + * state change unless the dependencies change.
3897 + *
3898 + * @return {Object} Data object returned by the `mapSelect` function.
3899 + */
3900 +
3901 +function useSuspenseSelect(mapSelect, deps) {
3902 + const _mapSelect = (0,external_wp_element_namespaceObject.useCallback)(mapSelect, deps);
3903 +
3904 + const registry = useRegistry();
3905 + const isAsync = useAsyncMode();
3906 + const latestRegistry = (0,external_wp_element_namespaceObject.useRef)(registry);
3907 + const latestMapSelect = (0,external_wp_element_namespaceObject.useRef)();
3908 + const latestIsAsync = (0,external_wp_element_namespaceObject.useRef)(isAsync);
3909 + const latestMapOutput = (0,external_wp_element_namespaceObject.useRef)();
3910 + const latestMapOutputError = (0,external_wp_element_namespaceObject.useRef)(); // Keep track of the stores being selected in the `mapSelect` function,
3911 + // and only subscribe to those stores later.
3912 +
3913 + const listeningStores = (0,external_wp_element_namespaceObject.useRef)([]);
3914 + const wrapSelect = (0,external_wp_element_namespaceObject.useCallback)(callback => registry.__unstableMarkListeningStores(() => callback(registry.suspendSelect, registry), listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
3915 + // It's different than just using `mapSelect` since deps could be undefined,
3916 + // in that case, we would still want to memoize it.
3917 +
3918 + const depsChangedFlag = (0,external_wp_element_namespaceObject.useMemo)(() => ({}), deps || []);
3919 + let mapOutput = latestMapOutput.current;
3920 + let mapOutputError = latestMapOutputError.current;
3921 + const hasReplacedRegistry = latestRegistry.current !== registry;
3922 + const hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;
3923 + const hasLeftAsyncMode = latestIsAsync.current && !isAsync;
3924 + let selectorRan = false;
3925 +
3926 + if (hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode) {
3927 + try {
3928 + mapOutput = wrapSelect(_mapSelect);
3929 + selectorRan = true;
3930 + } catch (error) {
3931 + mapOutputError = error;
3932 + }
3933 + }
3934 +
3935 + (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => {
3936 + latestRegistry.current = registry;
3937 + latestMapSelect.current = _mapSelect;
3938 + latestIsAsync.current = isAsync;
3939 +
3940 + if (selectorRan) {
3941 + latestMapOutput.current = mapOutput;
3942 + }
3943 +
3944 + latestMapOutputError.current = mapOutputError;
3945 + }); // React can sometimes clear the `useMemo` cache.
3946 + // We use the cache-stable `useMemoOne` to avoid
3947 + // losing queues.
3948 +
3949 + const queueContext = useMemoOne(() => ({
3950 + queue: true
3951 + }), [registry]);
3952 + const [, forceRender] = (0,external_wp_element_namespaceObject.useReducer)(s => s + 1, 0);
3953 + const isMounted = (0,external_wp_element_namespaceObject.useRef)(false);
3954 + (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => {
3955 + const onStoreChange = () => {
3956 + try {
3957 + const newMapOutput = wrapSelect(latestMapSelect.current);
3958 +
3959 + if (external_wp_isShallowEqual_default()(latestMapOutput.current, newMapOutput)) {
3960 + return;
3961 + }
3962 +
3963 + latestMapOutput.current = newMapOutput;
3964 + } catch (error) {
3965 + latestMapOutputError.current = error;
3966 + }
3967 +
3968 + forceRender();
3969 + };
3970 +
3971 + const onChange = () => {
3972 + if (!isMounted.current) {
3973 + return;
3974 + }
3975 +
3976 + if (latestIsAsync.current) {
3977 + renderQueue.add(queueContext, onStoreChange);
3978 + } else {
3979 + onStoreChange();
3980 + }
3981 + }; // catch any possible state changes during mount before the subscription
3982 + // could be set.
3983 +
3984 +
3985 + onStoreChange();
3986 + const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
3987 + isMounted.current = true;
3988 + return () => {
3989 + // The return value of the subscribe function could be undefined if the store is a custom generic store.
3990 + unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
3991 + renderQueue.cancel(queueContext);
3992 + isMounted.current = false;
3993 + };
3994 + }, [registry, wrapSelect, depsChangedFlag]);
3995 +
3996 + if (mapOutputError) {
3997 + throw mapOutputError;
3998 + }
3999 +
4000 + return mapOutput;
4001 +}
4002 +
3587 4003 ;// CONCATENATED MODULE: ./packages/data/build-module/components/with-select/index.js
3588 4004
3589 4005
3590 4006
@@ -3607,8 +4023,9 @@
3607 4023 *
3608 4024 * @example
3609 4025 * ```js
3610 4026 * import { withSelect } from '@wordpress/data';
4027 + * import { store as myCustomStore } from 'my-custom-store';
3611 4028 *
3612 4029 * function PriceDisplay( { price, currency } ) {
3613 4030 * return new Intl.NumberFormat( 'en-US', {
3614 4031 * style: 'currency',
@@ -3616,9 +4033,9 @@
3616 4033 * } ).format( price );
3617 4034 * }
3618 4035 *
3619 4036 * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
3620 - * const { getPrice } = select( 'my-shop' );
4037 + * const { getPrice } = select( myCustomStore );
3621 4038 * const { currency } = ownProps;
3622 4039 *
3623 4040 * return {
3624 4041 * price: getPrice( 'hammer', currency ),
@@ -3643,10 +4060,10 @@
3643 4060 const mergeProps = useSelect(mapSelect);
3644 4061 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, ownProps, mergeProps));
3645 4062 }), 'withSelect');
3646 4063
3647 -/* harmony default export */ var with_select = (withSelect);
3648 -//# sourceMappingURL=index.js.map
4064 +/* harmony default export */ const with_select = (withSelect);
4065 +
3649 4066 ;// CONCATENATED MODULE: ./packages/data/build-module/components/use-dispatch/use-dispatch-with-map.js
3650 4067 /**
3651 4068 * External dependencies
3652 4069 */
@@ -3697,10 +4114,10 @@
3697 4114 });
3698 4115 }, [registry, ...deps]);
3699 4116 };
3700 4117
3701 -/* harmony default export */ var use_dispatch_with_map = (useDispatchWithMap);
3702 -//# sourceMappingURL=use-dispatch-with-map.js.map
4118 +/* harmony default export */ const use_dispatch_with_map = (useDispatchWithMap);
4119 +
3703 4120 ;// CONCATENATED MODULE: ./packages/data/build-module/components/with-dispatch/index.js
3704 4121
3705 4122
3706 4123
@@ -3730,11 +4147,12 @@
3730 4147 * return <button type="button" onClick={ onClick }>{ children }</button>;
3731 4148 * }
3732 4149 *
3733 4150 * import { withDispatch } from '@wordpress/data';
4151 + * import { store as myCustomStore } from 'my-custom-store';
3734 4152 *
3735 4153 * const SaleButton = withDispatch( ( dispatch, ownProps ) => {
3736 - * const { startSale } = dispatch( 'my-shop' );
4154 + * const { startSale } = dispatch( myCustomStore );
3737 4155 * const { discountPercent } = ownProps;
3738 4156 *
3739 4157 * return {
3740 4158 * onClick() {
@@ -3767,13 +4185,14 @@
3767 4185 * return <button type="button" onClick={ onClick }>{ children }</button>;
3768 4186 * }
3769 4187 *
3770 4188 * import { withDispatch } from '@wordpress/data';
4189 + * import { store as myCustomStore } from 'my-custom-store';
3771 4190 *
3772 4191 * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
3773 4192 * // Stock number changes frequently.
3774 - * const { getStockNumber } = select( 'my-shop' );
3775 - * const { startSale } = dispatch( 'my-shop' );
4193 + * const { getStockNumber } = select( myCustomStore );
4194 + * const { startSale } = dispatch( myCustomStore );
3776 4195 * return {
3777 4196 * onClick() {
3778 4197 * const discountPercent = getStockNumber() > 50 ? 10 : 20;
3779 4198 * startSale( discountPercent );
@@ -3799,10 +4218,10 @@
3799 4218 const dispatchProps = use_dispatch_with_map(mapDispatch, []);
3800 4219 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, ownProps, dispatchProps));
3801 4220 }, 'withDispatch');
3802 4221
3803 -/* harmony default export */ var with_dispatch = (withDispatch);
3804 -//# sourceMappingURL=index.js.map
4222 +/* harmony default export */ const with_dispatch = (withDispatch);
4223 +
3805 4224 ;// CONCATENATED MODULE: ./packages/data/build-module/components/with-registry/index.js
3806 4225
3807 4226
3808 4227
@@ -3826,28 +4245,37 @@
3826 4245
3827 4246 const withRegistry = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => props => (0,external_wp_element_namespaceObject.createElement)(RegistryConsumer, null, registry => (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, props, {
3828 4247 registry: registry
3829 4248 }))), 'withRegistry');
3830 -/* harmony default export */ var with_registry = (withRegistry);
3831 -//# sourceMappingURL=index.js.map
4249 +/* harmony default export */ const with_registry = (withRegistry);
4250 +
3832 4251 ;// CONCATENATED MODULE: ./packages/data/build-module/components/use-dispatch/use-dispatch.js
3833 4252 /**
3834 4253 * Internal dependencies
3835 4254 */
3836 4255
3837 -/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */
4256 +/**
4257 + * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor
4258 + * @template StoreConfig
4259 + */
3838 4260
3839 4261 /**
4262 + * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn
4263 + * @template StoreNameOrDescriptor
4264 + */
4265 +
4266 +/**
3840 4267 * A custom react hook returning the current registry dispatch actions creators.
3841 4268 *
3842 4269 * Note: The component using this hook must be within the context of a
3843 4270 * RegistryProvider.
3844 4271 *
3845 - * @param {string|StoreDescriptor} [storeNameOrDescriptor] Optionally provide the name of the
3846 - * store or its descriptor from which to
3847 - * retrieve action creators. If not
3848 - * provided, the registry.dispatch
3849 - * function is returned instead.
4272 + * @template {undefined | string | StoreDescriptor<any>} [StoreNameOrDescriptor=undefined]
4273 + * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the
4274 + * store or its descriptor from which to
4275 + * retrieve action creators. If not
4276 + * provided, the registry.dispatch
4277 + * function is returned instead.
3850 4278 *
3851 4279 * @example
3852 4280 * This illustrates a pattern where you may need to retrieve dynamic data from
3853 4281 * the server via the `useSelect` hook to use in combination with the dispatch
@@ -3855,8 +4283,9 @@
3855 4283 *
3856 4284 * ```jsx
3857 4285 * import { useDispatch, useSelect } from '@wordpress/data';
3858 4286 * import { useCallback } from '@wordpress/element';
4287 + * import { store as myCustomStore } from 'my-custom-store';
3859 4288 *
3860 4289 * function Button( { onClick, children } ) {
3861 4290 * return <button type="button" onClick={ onClick }>{ children }</button>
3862 4291 * }
@@ -3862,12 +4291,12 @@
3862 4291 * }
3863 4292 *
3864 4293 * const SaleButton = ( { children } ) => {
3865 4294 * const { stockNumber } = useSelect(
3866 - * ( select ) => select( 'my-shop' ).getStockNumber(),
4295 + * ( select ) => select( myCustomStore ).getStockNumber(),
3867 4296 * []
3868 4297 * );
3869 - * const { startSale } = useDispatch( 'my-shop' );
4298 + * const { startSale } = useDispatch( myCustomStore );
3870 4299 * const onClick = useCallback( () => {
3871 4300 * const discountPercent = stockNumber > 50 ? 10: 20;
3872 4301 * startSale( discountPercent );
3873 4302 * }, [ stockNumber ] );
@@ -3877,9 +4306,9 @@
3877 4306 * // Rendered somewhere in the application:
3878 4307 * //
3879 4308 * // <SaleButton>Start Sale!</SaleButton>
3880 4309 * ```
3881 - * @return {Function} A custom react hook.
4310 + * @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.
3882 4311 */
3883 4312
3884 4313 const useDispatch = storeNameOrDescriptor => {
3885 4314 const {
@@ -3887,10 +4316,10 @@
3887 4316 } = useRegistry();
3888 4317 return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
3889 4318 };
3890 4319
3891 -/* harmony default export */ var use_dispatch = (useDispatch);
3892 -//# sourceMappingURL=use-dispatch.js.map
4320 +/* harmony default export */ const use_dispatch = (useDispatch);
4321 +
3893 4322 ;// CONCATENATED MODULE: ./packages/data/build-module/index.js
3894 4323 /**
3895 4324 * External dependencies
3896 4325 */
@@ -3926,8 +4355,9 @@
3926 4355 /**
3927 4356 * The combineReducers helper function turns an object whose values are different
3928 4357 * reducing functions into a single reducing function you can pass to registerReducer.
3929 4358 *
4359 + * @type {import('./types').combineReducers}
3930 4360 * @param {Object} reducers An object whose values correspond to different reducing
3931 4361 * functions that need to be combined into one.
3932 4362 *
3933 4363 * @example
@@ -3961,22 +4391,24 @@
3961 4391 * @return {Function} A reducer that invokes every reducer inside the reducers
3962 4392 * object, and constructs a state object with the same shape.
3963 4393 */
3964 4394
3965 -
4395 +const build_module_combineReducers = (turbo_combine_reducers_default());
3966 4396 /**
3967 - * Given the name or descriptor of a registered store, returns an object of the store's selectors.
4397 + * Given a store descriptor, returns an object of the store's selectors.
3968 4398 * The selector functions are been pre-bound to pass the current state automatically.
3969 4399 * As a consumer, you need only pass arguments of the selector, if applicable.
3970 4400 *
3971 - * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
3972 - * or the store descriptor.
4401 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
4402 + * convention of passing the store name is
4403 + * also supported.
3973 4404 *
3974 4405 * @example
3975 4406 * ```js
3976 4407 * import { select } from '@wordpress/data';
4408 + * import { store as myCustomStore } from 'my-custom-store';
3977 4409 *
3978 - * select( 'my-shop' ).getPrice( 'hammer' );
4410 + * select( myCustomStore ).getPrice( 'hammer' );
3979 4411 * ```
3980 4412 *
3981 4413 * @return {Object} Object containing the store's selectors.
3982 4414 */
@@ -3982,21 +4414,22 @@
3982 4414 */
3983 4415
3984 4416 const build_module_select = default_registry.select;
3985 4417 /**
3986 - * Given the name of a registered store, returns an object containing the store's
3987 - * selectors pre-bound to state so that you only need to supply additional arguments,
3988 - * and modified so that they return promises that resolve to their eventual values,
3989 - * after any resolvers have ran.
4418 + * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
4419 + * so that you only need to supply additional arguments, and modified so that they return promises
4420 + * that resolve to their eventual values, after any resolvers have ran.
3990 4421 *
3991 - * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
3992 - * or the store descriptor.
4422 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
4423 + * convention of passing the store name is
4424 + * also supported.
3993 4425 *
3994 4426 * @example
3995 4427 * ```js
3996 4428 * import { resolveSelect } from '@wordpress/data';
4429 + * import { store as myCustomStore } from 'my-custom-store';
3997 4430 *
3998 - * resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log)
4431 + * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)
3999 4432 * ```
4000 4433 *
4001 4434 * @return {Object} Object containing the store's promise-wrapped selectors.
4002 4435 */
@@ -4002,22 +4435,37 @@
4002 4435 */
4003 4436
4004 4437 const build_module_resolveSelect = default_registry.resolveSelect;
4005 4438 /**
4006 - * Given the name of a registered store, returns an object of the store's action creators.
4439 + * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
4440 + * so that you only need to supply additional arguments, and modified so that they throw promises
4441 + * in case the selector is not resolved yet.
4442 + *
4443 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
4444 + * convention of passing the store name is
4445 + * also supported.
4446 + *
4447 + * @return {Object} Object containing the store's suspense-wrapped selectors.
4448 + */
4449 +
4450 +const suspendSelect = default_registry.suspendSelect;
4451 +/**
4452 + * Given a store descriptor, returns an object of the store's action creators.
4007 4453 * Calling an action creator will cause it to be dispatched, updating the state value accordingly.
4008 4454 *
4009 4455 * Note: Action creators returned by the dispatch will return a promise when
4010 4456 * they are called.
4011 4457 *
4012 - * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
4013 - * or the store descriptor.
4458 + * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
4459 + * convention of passing the store name is
4460 + * also supported.
4014 4461 *
4015 4462 * @example
4016 4463 * ```js
4017 4464 * import { dispatch } from '@wordpress/data';
4465 + * import { store as myCustomStore } from 'my-custom-store';
4018 4466 *
4019 - * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
4467 + * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
4020 4468 * ```
4021 4469 * @return {Object} Object containing the action creators.
4022 4470 */
4023 4471
@@ -4094,9 +4542,10 @@
4094 4542 * @param {StoreDescriptor} store Store descriptor.
4095 4543 */
4096 4544
4097 4545 const register = default_registry.register;
4098 -//# sourceMappingURL=index.js.map
4099 -}();
4546 +
4547 +})();
4548 +
4100 4549 (window.wp = window.wp || {}).data = __webpack_exports__;
4101 4550 /******/ })()
4102 4551 ;