516 } |
479 } |
517 |
480 |
518 |
481 |
519 /***/ }), |
482 /***/ }), |
520 |
483 |
521 /***/ 163: |
484 /***/ "K9lf": |
522 /***/ (function(module, exports) { |
485 /***/ (function(module, exports) { |
523 |
486 |
524 function combineReducers( reducers ) { |
487 (function() { module.exports = window["wp"]["compose"]; }()); |
525 var keys = Object.keys( reducers ), |
|
526 getNextState; |
|
527 |
|
528 getNextState = ( function() { |
|
529 var fn, i, key; |
|
530 |
|
531 fn = 'return {'; |
|
532 for ( i = 0; i < keys.length; i++ ) { |
|
533 // Rely on Quoted escaping of JSON.stringify with guarantee that |
|
534 // each member of Object.keys is a string. |
|
535 // |
|
536 // "If Type(value) is String, then return the result of calling the |
|
537 // abstract operation Quote with argument value. [...] The abstract |
|
538 // operation Quote(value) wraps a String value in double quotes and |
|
539 // escapes characters within it." |
|
540 // |
|
541 // https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 |
|
542 key = JSON.stringify( keys[ i ] ); |
|
543 |
|
544 fn += key + ':r[' + key + '](s[' + key + '],a),'; |
|
545 } |
|
546 fn += '}'; |
|
547 |
|
548 return new Function( 'r,s,a', fn ); |
|
549 } )(); |
|
550 |
|
551 return function combinedReducer( state, action ) { |
|
552 var nextState, i, key; |
|
553 |
|
554 // Assumed changed if initial state. |
|
555 if ( state === undefined ) { |
|
556 return getNextState( reducers, {}, action ); |
|
557 } |
|
558 |
|
559 nextState = getNextState( reducers, state, action ); |
|
560 |
|
561 // Determine whether state has changed. |
|
562 i = keys.length; |
|
563 while ( i-- ) { |
|
564 key = keys[ i ]; |
|
565 if ( state[ key ] !== nextState[ key ] ) { |
|
566 // Return immediately if a changed value is encountered. |
|
567 return nextState; |
|
568 } |
|
569 } |
|
570 |
|
571 return state; |
|
572 }; |
|
573 } |
|
574 |
|
575 module.exports = combineReducers; |
|
576 |
|
577 |
488 |
578 /***/ }), |
489 /***/ }), |
579 |
490 |
580 /***/ 18: |
491 /***/ "NMb1": |
|
492 /***/ (function(module, exports) { |
|
493 |
|
494 (function() { module.exports = window["wp"]["deprecated"]; }()); |
|
495 |
|
496 /***/ }), |
|
497 |
|
498 /***/ "XI5e": |
|
499 /***/ (function(module, exports) { |
|
500 |
|
501 (function() { module.exports = window["wp"]["priorityQueue"]; }()); |
|
502 |
|
503 /***/ }), |
|
504 |
|
505 /***/ "XIDh": |
|
506 /***/ (function(module, exports) { |
|
507 |
|
508 (function() { module.exports = window["wp"]["reduxRoutine"]; }()); |
|
509 |
|
510 /***/ }), |
|
511 |
|
512 /***/ "YLtl": |
|
513 /***/ (function(module, exports) { |
|
514 |
|
515 (function() { module.exports = window["lodash"]; }()); |
|
516 |
|
517 /***/ }), |
|
518 |
|
519 /***/ "cDcd": |
|
520 /***/ (function(module, exports) { |
|
521 |
|
522 (function() { module.exports = window["React"]; }()); |
|
523 |
|
524 /***/ }), |
|
525 |
|
526 /***/ "mHlH": |
581 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
527 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
582 |
528 |
583 "use strict"; |
529 "use strict"; |
584 |
530 /* unused harmony export useCallback */ |
585 // EXPORTS |
531 /* unused harmony export useCallbackOne */ |
586 __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _toConsumableArray; }); |
532 /* unused harmony export useMemo */ |
587 |
533 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useMemoOne; }); |
588 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js |
534 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("cDcd"); |
589 var arrayLikeToArray = __webpack_require__(26); |
535 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
590 |
536 |
591 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js |
537 |
592 |
538 function areInputsEqual(newInputs, lastInputs) { |
593 function _arrayWithoutHoles(arr) { |
539 if (newInputs.length !== lastInputs.length) { |
594 if (Array.isArray(arr)) return Object(arrayLikeToArray["a" /* default */])(arr); |
540 return false; |
595 } |
541 } |
596 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js |
542 |
597 var iterableToArray = __webpack_require__(35); |
543 for (var i = 0; i < newInputs.length; i++) { |
598 |
544 if (newInputs[i] !== lastInputs[i]) { |
599 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js |
545 return false; |
600 var unsupportedIterableToArray = __webpack_require__(29); |
546 } |
601 |
547 } |
602 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js |
548 |
603 function _nonIterableSpread() { |
549 return true; |
604 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
550 } |
605 } |
551 |
606 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js |
552 function useMemoOne(getResult, inputs) { |
607 |
553 var initial = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(function () { |
608 |
554 return { |
609 |
555 inputs: inputs, |
610 |
556 result: getResult() |
611 function _toConsumableArray(arr) { |
557 }; |
612 return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || Object(unsupportedIterableToArray["a" /* default */])(arr) || _nonIterableSpread(); |
558 })[0]; |
613 } |
559 var isFirstRun = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(true); |
|
560 var committed = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(initial); |
|
561 var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
|
562 var cache = useCache ? committed.current : { |
|
563 inputs: inputs, |
|
564 result: getResult() |
|
565 }; |
|
566 Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(function () { |
|
567 isFirstRun.current = false; |
|
568 committed.current = cache; |
|
569 }, [cache]); |
|
570 return cache.result; |
|
571 } |
|
572 function useCallbackOne(callback, inputs) { |
|
573 return useMemoOne(function () { |
|
574 return callback; |
|
575 }, inputs); |
|
576 } |
|
577 var useMemo = useMemoOne; |
|
578 var useCallback = useCallbackOne; |
|
579 |
|
580 |
|
581 |
614 |
582 |
615 /***/ }), |
583 /***/ }), |
616 |
584 |
617 /***/ 196: |
585 /***/ "pfJ3": |
618 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
619 |
|
620 "use strict"; |
|
621 /* WEBPACK VAR INJECTION */(function(global, module) {/* harmony import */ var _ponyfill_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(275); |
|
622 /* global window */ |
|
623 |
|
624 |
|
625 var root; |
|
626 |
|
627 if (typeof self !== 'undefined') { |
|
628 root = self; |
|
629 } else if (typeof window !== 'undefined') { |
|
630 root = window; |
|
631 } else if (typeof global !== 'undefined') { |
|
632 root = global; |
|
633 } else if (true) { |
|
634 root = module; |
|
635 } else {} |
|
636 |
|
637 var result = Object(_ponyfill_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(root); |
|
638 /* harmony default export */ __webpack_exports__["a"] = (result); |
|
639 |
|
640 /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(127), __webpack_require__(412)(module))) |
|
641 |
|
642 /***/ }), |
|
643 |
|
644 /***/ 2: |
|
645 /***/ (function(module, exports) { |
|
646 |
|
647 (function() { module.exports = this["lodash"]; }()); |
|
648 |
|
649 /***/ }), |
|
650 |
|
651 /***/ 24: |
|
652 /***/ (function(module, exports) { |
|
653 |
|
654 (function() { module.exports = this["regeneratorRuntime"]; }()); |
|
655 |
|
656 /***/ }), |
|
657 |
|
658 /***/ 26: |
|
659 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
660 |
|
661 "use strict"; |
|
662 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayLikeToArray; }); |
|
663 function _arrayLikeToArray(arr, len) { |
|
664 if (len == null || len > arr.length) len = arr.length; |
|
665 |
|
666 for (var i = 0, arr2 = new Array(len); i < len; i++) { |
|
667 arr2[i] = arr[i]; |
|
668 } |
|
669 |
|
670 return arr2; |
|
671 } |
|
672 |
|
673 /***/ }), |
|
674 |
|
675 /***/ 274: |
|
676 /***/ (function(module, exports) { |
|
677 |
|
678 (function() { module.exports = this["wp"]["reduxRoutine"]; }()); |
|
679 |
|
680 /***/ }), |
|
681 |
|
682 /***/ 275: |
|
683 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
684 |
|
685 "use strict"; |
|
686 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return symbolObservablePonyfill; }); |
|
687 function symbolObservablePonyfill(root) { |
|
688 var result; |
|
689 var Symbol = root.Symbol; |
|
690 |
|
691 if (typeof Symbol === 'function') { |
|
692 if (Symbol.observable) { |
|
693 result = Symbol.observable; |
|
694 } else { |
|
695 result = Symbol('observable'); |
|
696 Symbol.observable = result; |
|
697 } |
|
698 } else { |
|
699 result = '@@observable'; |
|
700 } |
|
701 |
|
702 return result; |
|
703 }; |
|
704 |
|
705 |
|
706 /***/ }), |
|
707 |
|
708 /***/ 29: |
|
709 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
710 |
|
711 "use strict"; |
|
712 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _unsupportedIterableToArray; }); |
|
713 /* harmony import */ var _arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26); |
|
714 |
|
715 function _unsupportedIterableToArray(o, minLen) { |
|
716 if (!o) return; |
|
717 if (typeof o === "string") return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); |
|
718 var n = Object.prototype.toString.call(o).slice(8, -1); |
|
719 if (n === "Object" && o.constructor) n = o.constructor.name; |
|
720 if (n === "Map" || n === "Set") return Array.from(o); |
|
721 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); |
|
722 } |
|
723 |
|
724 /***/ }), |
|
725 |
|
726 /***/ 35: |
|
727 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
728 |
|
729 "use strict"; |
|
730 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; }); |
|
731 function _iterableToArray(iter) { |
|
732 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); |
|
733 } |
|
734 |
|
735 /***/ }), |
|
736 |
|
737 /***/ 37: |
|
738 /***/ (function(module, exports) { |
|
739 |
|
740 (function() { module.exports = this["wp"]["deprecated"]; }()); |
|
741 |
|
742 /***/ }), |
|
743 |
|
744 /***/ 38: |
|
745 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
746 |
|
747 "use strict"; |
|
748 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayWithHoles; }); |
|
749 function _arrayWithHoles(arr) { |
|
750 if (Array.isArray(arr)) return arr; |
|
751 } |
|
752 |
|
753 /***/ }), |
|
754 |
|
755 /***/ 39: |
|
756 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
757 |
|
758 "use strict"; |
|
759 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _nonIterableRest; }); |
|
760 function _nonIterableRest() { |
|
761 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
|
762 } |
|
763 |
|
764 /***/ }), |
|
765 |
|
766 /***/ 412: |
|
767 /***/ (function(module, exports) { |
|
768 |
|
769 module.exports = function(originalModule) { |
|
770 if (!originalModule.webpackPolyfill) { |
|
771 var module = Object.create(originalModule); |
|
772 // module.parent = undefined by default |
|
773 if (!module.children) module.children = []; |
|
774 Object.defineProperty(module, "loaded", { |
|
775 enumerable: true, |
|
776 get: function() { |
|
777 return module.l; |
|
778 } |
|
779 }); |
|
780 Object.defineProperty(module, "id", { |
|
781 enumerable: true, |
|
782 get: function() { |
|
783 return module.i; |
|
784 } |
|
785 }); |
|
786 Object.defineProperty(module, "exports", { |
|
787 enumerable: true |
|
788 }); |
|
789 module.webpackPolyfill = 1; |
|
790 } |
|
791 return module; |
|
792 }; |
|
793 |
|
794 |
|
795 /***/ }), |
|
796 |
|
797 /***/ 442: |
|
798 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
586 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
799 |
587 |
800 "use strict"; |
588 "use strict"; |
801 // ESM COMPAT FLAG |
589 // ESM COMPAT FLAG |
802 __webpack_require__.r(__webpack_exports__); |
590 __webpack_require__.r(__webpack_exports__); |
808 __webpack_require__.d(__webpack_exports__, "RegistryProvider", function() { return /* reexport */ context; }); |
596 __webpack_require__.d(__webpack_exports__, "RegistryProvider", function() { return /* reexport */ context; }); |
809 __webpack_require__.d(__webpack_exports__, "RegistryConsumer", function() { return /* reexport */ RegistryConsumer; }); |
597 __webpack_require__.d(__webpack_exports__, "RegistryConsumer", function() { return /* reexport */ RegistryConsumer; }); |
810 __webpack_require__.d(__webpack_exports__, "useRegistry", function() { return /* reexport */ useRegistry; }); |
598 __webpack_require__.d(__webpack_exports__, "useRegistry", function() { return /* reexport */ useRegistry; }); |
811 __webpack_require__.d(__webpack_exports__, "useSelect", function() { return /* reexport */ useSelect; }); |
599 __webpack_require__.d(__webpack_exports__, "useSelect", function() { return /* reexport */ useSelect; }); |
812 __webpack_require__.d(__webpack_exports__, "useDispatch", function() { return /* reexport */ use_dispatch; }); |
600 __webpack_require__.d(__webpack_exports__, "useDispatch", function() { return /* reexport */ use_dispatch; }); |
813 __webpack_require__.d(__webpack_exports__, "__unstableUseDispatchWithMap", function() { return /* reexport */ use_dispatch_with_map; }); |
|
814 __webpack_require__.d(__webpack_exports__, "AsyncModeProvider", function() { return /* reexport */ async_mode_provider_context; }); |
601 __webpack_require__.d(__webpack_exports__, "AsyncModeProvider", function() { return /* reexport */ async_mode_provider_context; }); |
815 __webpack_require__.d(__webpack_exports__, "createRegistry", function() { return /* reexport */ createRegistry; }); |
602 __webpack_require__.d(__webpack_exports__, "createRegistry", function() { return /* reexport */ createRegistry; }); |
816 __webpack_require__.d(__webpack_exports__, "createRegistrySelector", function() { return /* reexport */ createRegistrySelector; }); |
603 __webpack_require__.d(__webpack_exports__, "createRegistrySelector", function() { return /* reexport */ createRegistrySelector; }); |
817 __webpack_require__.d(__webpack_exports__, "createRegistryControl", function() { return /* reexport */ createRegistryControl; }); |
604 __webpack_require__.d(__webpack_exports__, "createRegistryControl", function() { return /* reexport */ createRegistryControl; }); |
|
605 __webpack_require__.d(__webpack_exports__, "controls", function() { return /* reexport */ controls_controls; }); |
|
606 __webpack_require__.d(__webpack_exports__, "createReduxStore", function() { return /* reexport */ createReduxStore; }); |
818 __webpack_require__.d(__webpack_exports__, "plugins", function() { return /* reexport */ plugins_namespaceObject; }); |
607 __webpack_require__.d(__webpack_exports__, "plugins", function() { return /* reexport */ plugins_namespaceObject; }); |
819 __webpack_require__.d(__webpack_exports__, "combineReducers", function() { return /* reexport */ turbo_combine_reducers_default.a; }); |
608 __webpack_require__.d(__webpack_exports__, "combineReducers", function() { return /* reexport */ turbo_combine_reducers_default.a; }); |
820 __webpack_require__.d(__webpack_exports__, "select", function() { return /* binding */ build_module_select; }); |
609 __webpack_require__.d(__webpack_exports__, "select", function() { return /* binding */ build_module_select; }); |
821 __webpack_require__.d(__webpack_exports__, "__experimentalResolveSelect", function() { return /* binding */ build_module_experimentalResolveSelect; }); |
610 __webpack_require__.d(__webpack_exports__, "resolveSelect", function() { return /* binding */ build_module_resolveSelect; }); |
822 __webpack_require__.d(__webpack_exports__, "dispatch", function() { return /* binding */ build_module_dispatch; }); |
611 __webpack_require__.d(__webpack_exports__, "dispatch", function() { return /* binding */ build_module_dispatch; }); |
823 __webpack_require__.d(__webpack_exports__, "subscribe", function() { return /* binding */ build_module_subscribe; }); |
612 __webpack_require__.d(__webpack_exports__, "subscribe", function() { return /* binding */ build_module_subscribe; }); |
824 __webpack_require__.d(__webpack_exports__, "registerGenericStore", function() { return /* binding */ build_module_registerGenericStore; }); |
613 __webpack_require__.d(__webpack_exports__, "registerGenericStore", function() { return /* binding */ build_module_registerGenericStore; }); |
825 __webpack_require__.d(__webpack_exports__, "registerStore", function() { return /* binding */ build_module_registerStore; }); |
614 __webpack_require__.d(__webpack_exports__, "registerStore", function() { return /* binding */ registerStore; }); |
826 __webpack_require__.d(__webpack_exports__, "use", function() { return /* binding */ build_module_use; }); |
615 __webpack_require__.d(__webpack_exports__, "use", function() { return /* binding */ build_module_use; }); |
827 |
616 __webpack_require__.d(__webpack_exports__, "register", function() { return /* binding */ build_module_register; }); |
828 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/namespace-store/metadata/selectors.js |
617 |
|
618 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
829 var selectors_namespaceObject = {}; |
619 var selectors_namespaceObject = {}; |
830 __webpack_require__.r(selectors_namespaceObject); |
620 __webpack_require__.r(selectors_namespaceObject); |
831 __webpack_require__.d(selectors_namespaceObject, "getIsResolving", function() { return getIsResolving; }); |
621 __webpack_require__.d(selectors_namespaceObject, "getIsResolving", function() { return getIsResolving; }); |
832 __webpack_require__.d(selectors_namespaceObject, "hasStartedResolution", function() { return hasStartedResolution; }); |
622 __webpack_require__.d(selectors_namespaceObject, "hasStartedResolution", function() { return hasStartedResolution; }); |
833 __webpack_require__.d(selectors_namespaceObject, "hasFinishedResolution", function() { return hasFinishedResolution; }); |
623 __webpack_require__.d(selectors_namespaceObject, "hasFinishedResolution", function() { return hasFinishedResolution; }); |
834 __webpack_require__.d(selectors_namespaceObject, "isResolving", function() { return isResolving; }); |
624 __webpack_require__.d(selectors_namespaceObject, "isResolving", function() { return isResolving; }); |
835 __webpack_require__.d(selectors_namespaceObject, "getCachedResolvers", function() { return getCachedResolvers; }); |
625 __webpack_require__.d(selectors_namespaceObject, "getCachedResolvers", function() { return getCachedResolvers; }); |
836 |
626 |
837 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/namespace-store/metadata/actions.js |
627 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js |
838 var actions_namespaceObject = {}; |
628 var actions_namespaceObject = {}; |
839 __webpack_require__.r(actions_namespaceObject); |
629 __webpack_require__.r(actions_namespaceObject); |
840 __webpack_require__.d(actions_namespaceObject, "startResolution", function() { return startResolution; }); |
630 __webpack_require__.d(actions_namespaceObject, "startResolution", function() { return startResolution; }); |
841 __webpack_require__.d(actions_namespaceObject, "finishResolution", function() { return finishResolution; }); |
631 __webpack_require__.d(actions_namespaceObject, "finishResolution", function() { return finishResolution; }); |
|
632 __webpack_require__.d(actions_namespaceObject, "startResolutions", function() { return startResolutions; }); |
|
633 __webpack_require__.d(actions_namespaceObject, "finishResolutions", function() { return finishResolutions; }); |
842 __webpack_require__.d(actions_namespaceObject, "invalidateResolution", function() { return invalidateResolution; }); |
634 __webpack_require__.d(actions_namespaceObject, "invalidateResolution", function() { return invalidateResolution; }); |
843 __webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStore", function() { return invalidateResolutionForStore; }); |
635 __webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStore", function() { return invalidateResolutionForStore; }); |
844 __webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStoreSelector", function() { return invalidateResolutionForStoreSelector; }); |
636 __webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStoreSelector", function() { return invalidateResolutionForStoreSelector; }); |
845 |
637 |
846 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js |
638 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js |
847 var plugins_namespaceObject = {}; |
639 var plugins_namespaceObject = {}; |
848 __webpack_require__.r(plugins_namespaceObject); |
640 __webpack_require__.r(plugins_namespaceObject); |
849 __webpack_require__.d(plugins_namespaceObject, "controls", function() { return controls; }); |
641 __webpack_require__.d(plugins_namespaceObject, "controls", function() { return plugins_controls; }); |
850 __webpack_require__.d(plugins_namespaceObject, "persistence", function() { return plugins_persistence; }); |
642 __webpack_require__.d(plugins_namespaceObject, "persistence", function() { return plugins_persistence; }); |
851 |
643 |
852 // EXTERNAL MODULE: ./node_modules/turbo-combine-reducers/index.js |
644 // EXTERNAL MODULE: ./node_modules/turbo-combine-reducers/index.js |
853 var turbo_combine_reducers = __webpack_require__(163); |
645 var turbo_combine_reducers = __webpack_require__("8mpt"); |
854 var turbo_combine_reducers_default = /*#__PURE__*/__webpack_require__.n(turbo_combine_reducers); |
646 var turbo_combine_reducers_default = /*#__PURE__*/__webpack_require__.n(turbo_combine_reducers); |
855 |
647 |
856 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js + 1 modules |
648 // EXTERNAL MODULE: external "lodash" |
857 var slicedToArray = __webpack_require__(14); |
649 var external_lodash_ = __webpack_require__("YLtl"); |
858 |
650 |
859 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
651 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
860 var defineProperty = __webpack_require__(5); |
652 function _defineProperty(obj, key, value) { |
861 |
653 if (key in obj) { |
862 // EXTERNAL MODULE: external {"this":"lodash"} |
654 Object.defineProperty(obj, key, { |
863 var external_this_lodash_ = __webpack_require__(2); |
655 value: value, |
864 |
656 enumerable: true, |
865 // EXTERNAL MODULE: ./node_modules/memize/index.js |
657 configurable: true, |
866 var memize = __webpack_require__(60); |
658 writable: true |
867 var memize_default = /*#__PURE__*/__webpack_require__.n(memize); |
659 }); |
868 |
660 } else { |
869 // EXTERNAL MODULE: external {"this":"regeneratorRuntime"} |
661 obj[key] = value; |
870 var external_this_regeneratorRuntime_ = __webpack_require__(24); |
662 } |
871 var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_); |
663 |
872 |
664 return obj; |
873 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js |
665 } |
874 var asyncToGenerator = __webpack_require__(50); |
666 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js |
875 |
667 |
876 // EXTERNAL MODULE: ./node_modules/symbol-observable/es/index.js |
668 |
877 var es = __webpack_require__(196); |
669 function ownKeys(object, enumerableOnly) { |
878 |
670 var keys = Object.keys(object); |
|
671 |
|
672 if (Object.getOwnPropertySymbols) { |
|
673 var symbols = Object.getOwnPropertySymbols(object); |
|
674 |
|
675 if (enumerableOnly) { |
|
676 symbols = symbols.filter(function (sym) { |
|
677 return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
|
678 }); |
|
679 } |
|
680 |
|
681 keys.push.apply(keys, symbols); |
|
682 } |
|
683 |
|
684 return keys; |
|
685 } |
|
686 |
|
687 function _objectSpread2(target) { |
|
688 for (var i = 1; i < arguments.length; i++) { |
|
689 var source = arguments[i] != null ? arguments[i] : {}; |
|
690 |
|
691 if (i % 2) { |
|
692 ownKeys(Object(source), true).forEach(function (key) { |
|
693 _defineProperty(target, key, source[key]); |
|
694 }); |
|
695 } else if (Object.getOwnPropertyDescriptors) { |
|
696 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); |
|
697 } else { |
|
698 ownKeys(Object(source)).forEach(function (key) { |
|
699 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
|
700 }); |
|
701 } |
|
702 } |
|
703 |
|
704 return target; |
|
705 } |
879 // CONCATENATED MODULE: ./node_modules/redux/es/redux.js |
706 // CONCATENATED MODULE: ./node_modules/redux/es/redux.js |
880 |
707 |
|
708 |
|
709 /** |
|
710 * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js |
|
711 * |
|
712 * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes |
|
713 * during build. |
|
714 * @param {number} code |
|
715 */ |
|
716 function formatProdErrorMessage(code) { |
|
717 return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. '; |
|
718 } |
|
719 |
|
720 // Inlined version of the `symbol-observable` polyfill |
|
721 var $$observable = (function () { |
|
722 return typeof Symbol === 'function' && Symbol.observable || '@@observable'; |
|
723 })(); |
881 |
724 |
882 /** |
725 /** |
883 * These are private action types reserved by Redux. |
726 * These are private action types reserved by Redux. |
884 * For any unknown actions, you must return the current state. |
727 * For any unknown actions, you must return the current state. |
885 * If the current state is undefined, you must return the initial state. |
728 * If the current state is undefined, you must return the initial state. |
1525 |
1371 |
1526 if (false) {} |
1372 if (false) {} |
1527 |
1373 |
1528 |
1374 |
1529 |
1375 |
1530 // EXTERNAL MODULE: external {"this":["wp","reduxRoutine"]} |
1376 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
1531 var external_this_wp_reduxRoutine_ = __webpack_require__(274); |
1377 var equivalent_key_map = __webpack_require__("FtRg"); |
1532 var external_this_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_reduxRoutine_); |
1378 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
|
1379 |
|
1380 // EXTERNAL MODULE: external ["wp","reduxRoutine"] |
|
1381 var external_wp_reduxRoutine_ = __webpack_require__("XIDh"); |
|
1382 var external_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_wp_reduxRoutine_); |
|
1383 |
|
1384 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/factory.js |
|
1385 /** |
|
1386 * Creates a selector function that takes additional curried argument with the |
|
1387 * registry `select` function. While a regular selector has signature |
|
1388 * ```js |
|
1389 * ( state, ...selectorArgs ) => ( result ) |
|
1390 * ``` |
|
1391 * that allows to select data from the store's `state`, a registry selector |
|
1392 * has signature: |
|
1393 * ```js |
|
1394 * ( select ) => ( state, ...selectorArgs ) => ( result ) |
|
1395 * ``` |
|
1396 * that supports also selecting from other registered stores. |
|
1397 * |
|
1398 * @example |
|
1399 * ```js |
|
1400 * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => { |
|
1401 * return select( 'core/editor' ).getCurrentPostId(); |
|
1402 * } ); |
|
1403 * |
|
1404 * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => { |
|
1405 * // calling another registry selector just like any other function |
|
1406 * const postType = getCurrentPostType( state ); |
|
1407 * const postId = getCurrentPostId( state ); |
|
1408 * return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId ); |
|
1409 * } ); |
|
1410 * ``` |
|
1411 * |
|
1412 * Note how the `getCurrentPostId` selector can be called just like any other function, |
|
1413 * (it works even inside a regular non-registry selector) and we don't need to pass the |
|
1414 * registry as argument. The registry binding happens automatically when registering the selector |
|
1415 * with a store. |
|
1416 * |
|
1417 * @param {Function} registrySelector Function receiving a registry `select` |
|
1418 * function and returning a state selector. |
|
1419 * |
|
1420 * @return {Function} Registry selector that can be registered with a store. |
|
1421 */ |
|
1422 function createRegistrySelector(registrySelector) { |
|
1423 // create a selector function that is bound to the registry referenced by `selector.registry` |
|
1424 // and that has the same API as a regular selector. Binding it in such a way makes it |
|
1425 // possible to call the selector directly from another selector. |
|
1426 const selector = (...args) => registrySelector(selector.registry.select)(...args); |
|
1427 /** |
|
1428 * Flag indicating that the selector is a registry selector that needs the correct registry |
|
1429 * reference to be assigned to `selecto.registry` to make it work correctly. |
|
1430 * be mapped as a registry selector. |
|
1431 * |
|
1432 * @type {boolean} |
|
1433 */ |
|
1434 |
|
1435 |
|
1436 selector.isRegistrySelector = true; |
|
1437 return selector; |
|
1438 } |
|
1439 /** |
|
1440 * Creates a control function that takes additional curried argument with the `registry` object. |
|
1441 * While a regular control has signature |
|
1442 * ```js |
|
1443 * ( action ) => ( iteratorOrPromise ) |
|
1444 * ``` |
|
1445 * where the control works with the `action` that it's bound to, a registry control has signature: |
|
1446 * ```js |
|
1447 * ( registry ) => ( action ) => ( iteratorOrPromise ) |
|
1448 * ``` |
|
1449 * A registry control is typically used to select data or dispatch an action to a registered |
|
1450 * store. |
|
1451 * |
|
1452 * When registering a control created with `createRegistryControl` with a store, the store |
|
1453 * knows which calling convention to use when executing the control. |
|
1454 * |
|
1455 * @param {Function} registryControl Function receiving a registry object and returning a control. |
|
1456 * |
|
1457 * @return {Function} Registry control that can be registered with a store. |
|
1458 */ |
|
1459 |
|
1460 function createRegistryControl(registryControl) { |
|
1461 registryControl.isRegistryControl = true; |
|
1462 return registryControl; |
|
1463 } |
|
1464 |
|
1465 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/controls.js |
|
1466 /** |
|
1467 * Internal dependencies |
|
1468 */ |
|
1469 |
|
1470 const SELECT = '@@data/SELECT'; |
|
1471 const RESOLVE_SELECT = '@@data/RESOLVE_SELECT'; |
|
1472 const DISPATCH = '@@data/DISPATCH'; |
|
1473 /** |
|
1474 * Dispatches a control action for triggering a synchronous registry select. |
|
1475 * |
|
1476 * Note: This control synchronously returns the current selector value, triggering the |
|
1477 * resolution, but not waiting for it. |
|
1478 * |
|
1479 * @param {string} storeKey The key for the store the selector belongs to. |
|
1480 * @param {string} selectorName The name of the selector. |
|
1481 * @param {Array} args Arguments for the selector. |
|
1482 * |
|
1483 * @example |
|
1484 * ```js |
|
1485 * import { controls } from '@wordpress/data'; |
|
1486 * |
|
1487 * // Action generator using `select`. |
|
1488 * export function* myAction() { |
|
1489 * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' ); |
|
1490 * // Do stuff with the result from the `select`. |
|
1491 * } |
|
1492 * ``` |
|
1493 * |
|
1494 * @return {Object} The control descriptor. |
|
1495 */ |
|
1496 |
|
1497 function controls_select(storeKey, selectorName, ...args) { |
|
1498 return { |
|
1499 type: SELECT, |
|
1500 storeKey, |
|
1501 selectorName, |
|
1502 args |
|
1503 }; |
|
1504 } |
|
1505 /** |
|
1506 * Dispatches a control action for triggering and resolving a registry select. |
|
1507 * |
|
1508 * Note: when this control action is handled, it automatically considers |
|
1509 * selectors that may have a resolver. In such case, it will return a `Promise` that resolves |
|
1510 * after the selector finishes resolving, with the final result value. |
|
1511 * |
|
1512 * @param {string} storeKey The key for the store the selector belongs to |
|
1513 * @param {string} selectorName The name of the selector |
|
1514 * @param {Array} args Arguments for the selector. |
|
1515 * |
|
1516 * @example |
|
1517 * ```js |
|
1518 * import { controls } from '@wordpress/data'; |
|
1519 * |
|
1520 * // Action generator using resolveSelect |
|
1521 * export function* myAction() { |
|
1522 * const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' ); |
|
1523 * // do stuff with the result from the select. |
|
1524 * } |
|
1525 * ``` |
|
1526 * |
|
1527 * @return {Object} The control descriptor. |
|
1528 */ |
|
1529 |
|
1530 |
|
1531 function controls_resolveSelect(storeKey, selectorName, ...args) { |
|
1532 return { |
|
1533 type: RESOLVE_SELECT, |
|
1534 storeKey, |
|
1535 selectorName, |
|
1536 args |
|
1537 }; |
|
1538 } |
|
1539 /** |
|
1540 * Dispatches a control action for triggering a registry dispatch. |
|
1541 * |
|
1542 * @param {string} storeKey The key for the store the action belongs to |
|
1543 * @param {string} actionName The name of the action to dispatch |
|
1544 * @param {Array} args Arguments for the dispatch action. |
|
1545 * |
|
1546 * @example |
|
1547 * ```js |
|
1548 * import { controls } from '@wordpress/data-controls'; |
|
1549 * |
|
1550 * // Action generator using dispatch |
|
1551 * export function* myAction() { |
|
1552 * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' ); |
|
1553 * // do some other things. |
|
1554 * } |
|
1555 * ``` |
|
1556 * |
|
1557 * @return {Object} The control descriptor. |
|
1558 */ |
|
1559 |
|
1560 |
|
1561 function controls_dispatch(storeKey, actionName, ...args) { |
|
1562 return { |
|
1563 type: DISPATCH, |
|
1564 storeKey, |
|
1565 actionName, |
|
1566 args |
|
1567 }; |
|
1568 } |
|
1569 |
|
1570 const controls_controls = { |
|
1571 select: controls_select, |
|
1572 resolveSelect: controls_resolveSelect, |
|
1573 dispatch: controls_dispatch |
|
1574 }; |
|
1575 const builtinControls = { |
|
1576 [SELECT]: createRegistryControl(registry => ({ |
|
1577 storeKey, |
|
1578 selectorName, |
|
1579 args |
|
1580 }) => registry.select(storeKey)[selectorName](...args)), |
|
1581 [RESOLVE_SELECT]: createRegistryControl(registry => ({ |
|
1582 storeKey, |
|
1583 selectorName, |
|
1584 args |
|
1585 }) => { |
|
1586 const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select'; |
|
1587 return registry[method](storeKey)[selectorName](...args); |
|
1588 }), |
|
1589 [DISPATCH]: createRegistryControl(registry => ({ |
|
1590 storeKey, |
|
1591 actionName, |
|
1592 args |
|
1593 }) => registry.dispatch(storeKey)[actionName](...args)) |
|
1594 }; |
1533 |
1595 |
1534 // EXTERNAL MODULE: ./node_modules/is-promise/index.js |
1596 // EXTERNAL MODULE: ./node_modules/is-promise/index.js |
1535 var is_promise = __webpack_require__(151); |
1597 var is_promise = __webpack_require__("JlUD"); |
1536 var is_promise_default = /*#__PURE__*/__webpack_require__.n(is_promise); |
1598 var is_promise_default = /*#__PURE__*/__webpack_require__.n(is_promise); |
1537 |
1599 |
1538 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/promise-middleware.js |
1600 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/promise-middleware.js |
1539 /** |
1601 /** |
1540 * External dependencies |
1602 * External dependencies |
1586 * middleware. |
1638 * middleware. |
1587 * |
1639 * |
1588 * @return {Function} Middleware function. |
1640 * @return {Function} Middleware function. |
1589 */ |
1641 */ |
1590 |
1642 |
1591 var resolvers_cache_middleware_createResolversCacheMiddleware = function createResolversCacheMiddleware(registry, reducerKey) { |
1643 const createResolversCacheMiddleware = (registry, reducerKey) => () => next => action => { |
1592 return function () { |
1644 const resolvers = registry.select('core/data').getCachedResolvers(reducerKey); |
1593 return function (next) { |
1645 Object.entries(resolvers).forEach(([selectorName, resolversByArgs]) => { |
1594 return function (action) { |
1646 const resolver = Object(external_lodash_["get"])(registry.stores, [reducerKey, 'resolvers', selectorName]); |
1595 var resolvers = registry.select('core/data').getCachedResolvers(reducerKey); |
1647 |
1596 Object.entries(resolvers).forEach(function (_ref) { |
1648 if (!resolver || !resolver.shouldInvalidate) { |
1597 var _ref2 = Object(slicedToArray["a" /* default */])(_ref, 2), |
1649 return; |
1598 selectorName = _ref2[0], |
1650 } |
1599 resolversByArgs = _ref2[1]; |
1651 |
1600 |
1652 resolversByArgs.forEach((value, args) => { |
1601 var resolver = Object(external_this_lodash_["get"])(registry.stores, [reducerKey, 'resolvers', selectorName]); |
1653 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
1602 |
1654 // If the value is false it means this resolver has finished its resolution which means we need to invalidate it, |
1603 if (!resolver || !resolver.shouldInvalidate) { |
1655 // if it's true it means it's inflight and the invalidation is not necessary. |
1604 return; |
1656 if (value !== false || !resolver.shouldInvalidate(action, ...args)) { |
1605 } |
1657 return; |
1606 |
1658 } // Trigger cache invalidation |
1607 resolversByArgs.forEach(function (value, args) { |
1659 |
1608 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
1660 |
1609 // If the value is false it means this resolver has finished its resolution which means we need to invalidate it, |
1661 registry.dispatch('core/data').invalidateResolution(reducerKey, selectorName, args); |
1610 // if it's true it means it's inflight and the invalidation is not necessary. |
1662 }); |
1611 if (value !== false || !resolver.shouldInvalidate.apply(resolver, [action].concat(Object(toConsumableArray["a" /* default */])(args)))) { |
1663 }); |
1612 return; |
1664 return next(action); |
1613 } // Trigger cache invalidation |
1665 }; |
1614 |
1666 |
1615 |
1667 /* harmony default export */ var resolvers_cache_middleware = (createResolversCacheMiddleware); |
1616 registry.dispatch('core/data').invalidateResolution(reducerKey, selectorName, args); |
1668 |
1617 }); |
1669 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/thunk-middleware.js |
1618 }); |
1670 function createThunkMiddleware(args) { |
1619 return next(action); |
1671 return () => next => action => { |
1620 }; |
1672 if (typeof action === 'function') { |
1621 }; |
1673 return action(args); |
|
1674 } |
|
1675 |
|
1676 return next(action); |
|
1677 }; |
|
1678 } |
|
1679 |
|
1680 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/utils.js |
|
1681 /** |
|
1682 * Higher-order reducer creator which creates a combined reducer object, keyed |
|
1683 * by a property on the action object. |
|
1684 * |
|
1685 * @param {string} actionProperty Action property by which to key object. |
|
1686 * |
|
1687 * @return {Function} Higher-order reducer. |
|
1688 */ |
|
1689 const onSubKey = actionProperty => reducer => (state = {}, action) => { |
|
1690 // Retrieve subkey from action. Do not track if undefined; useful for cases |
|
1691 // where reducer is scoped by action shape. |
|
1692 const key = action[actionProperty]; |
|
1693 |
|
1694 if (key === undefined) { |
|
1695 return state; |
|
1696 } // Avoid updating state if unchanged. Note that this also accounts for a |
|
1697 // reducer which returns undefined on a key which is not yet tracked. |
|
1698 |
|
1699 |
|
1700 const nextKeyState = reducer(state[key], action); |
|
1701 |
|
1702 if (nextKeyState === state[key]) { |
|
1703 return state; |
|
1704 } |
|
1705 |
|
1706 return { ...state, |
|
1707 [key]: nextKeyState |
1622 }; |
1708 }; |
1623 }; |
1709 }; |
1624 |
1710 |
1625 /* harmony default export */ var resolvers_cache_middleware = (resolvers_cache_middleware_createResolversCacheMiddleware); |
1711 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/reducer.js |
1626 |
|
1627 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
|
1628 var equivalent_key_map = __webpack_require__(126); |
|
1629 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
|
1630 |
|
1631 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/namespace-store/metadata/utils.js |
|
1632 |
|
1633 |
|
1634 function utils_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
1635 |
|
1636 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { utils_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { utils_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
1637 |
|
1638 /** |
|
1639 * Higher-order reducer creator which creates a combined reducer object, keyed |
|
1640 * by a property on the action object. |
|
1641 * |
|
1642 * @param {string} actionProperty Action property by which to key object. |
|
1643 * |
|
1644 * @return {Function} Higher-order reducer. |
|
1645 */ |
|
1646 var utils_onSubKey = function onSubKey(actionProperty) { |
|
1647 return function (reducer) { |
|
1648 return function () { |
|
1649 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
1650 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
1651 // Retrieve subkey from action. Do not track if undefined; useful for cases |
|
1652 // where reducer is scoped by action shape. |
|
1653 var key = action[actionProperty]; |
|
1654 |
|
1655 if (key === undefined) { |
|
1656 return state; |
|
1657 } // Avoid updating state if unchanged. Note that this also accounts for a |
|
1658 // reducer which returns undefined on a key which is not yet tracked. |
|
1659 |
|
1660 |
|
1661 var nextKeyState = reducer(state[key], action); |
|
1662 |
|
1663 if (nextKeyState === state[key]) { |
|
1664 return state; |
|
1665 } |
|
1666 |
|
1667 return _objectSpread({}, state, Object(defineProperty["a" /* default */])({}, key, nextKeyState)); |
|
1668 }; |
|
1669 }; |
|
1670 }; |
|
1671 |
|
1672 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/namespace-store/metadata/reducer.js |
|
1673 /** |
1712 /** |
1674 * External dependencies |
1713 * External dependencies |
1675 */ |
1714 */ |
1676 |
1715 |
1677 |
1716 |
1941 |
2013 |
1942 |
2014 |
1943 |
2015 |
1944 |
2016 |
1945 |
2017 |
1946 /** |
2018 |
1947 * @typedef {WPDataRegistry} WPDataRegistry |
2019 |
1948 */ |
2020 /** @typedef {import('../types').WPDataRegistry} WPDataRegistry */ |
1949 |
2021 |
1950 /** |
2022 /** @typedef {import('../types').WPDataStore} WPDataStore */ |
1951 * Creates a namespace object with a store derived from the reducer given. |
2023 |
|
2024 /** @typedef {import('../types').WPDataReduxStoreConfig} WPDataReduxStoreConfig */ |
|
2025 |
|
2026 /** |
|
2027 * Create a cache to track whether resolvers started running or not. |
|
2028 * |
|
2029 * @return {Object} Resolvers Cache. |
|
2030 */ |
|
2031 |
|
2032 function createResolversCache() { |
|
2033 const cache = {}; |
|
2034 return { |
|
2035 isRunning(selectorName, args) { |
|
2036 return cache[selectorName] && cache[selectorName].get(args); |
|
2037 }, |
|
2038 |
|
2039 clear(selectorName, args) { |
|
2040 if (cache[selectorName]) { |
|
2041 cache[selectorName].delete(args); |
|
2042 } |
|
2043 }, |
|
2044 |
|
2045 markAsRunning(selectorName, args) { |
|
2046 if (!cache[selectorName]) { |
|
2047 cache[selectorName] = new equivalent_key_map_default.a(); |
|
2048 } |
|
2049 |
|
2050 cache[selectorName].set(args, true); |
|
2051 } |
|
2052 |
|
2053 }; |
|
2054 } |
|
2055 /** |
|
2056 * Creates a data store definition for the provided Redux store options containing |
|
2057 * properties describing reducer, actions, selectors, controls and resolvers. |
|
2058 * |
|
2059 * @example |
|
2060 * ```js |
|
2061 * import { createReduxStore } from '@wordpress/data'; |
|
2062 * |
|
2063 * const store = createReduxStore( 'demo', { |
|
2064 * reducer: ( state = 'OK' ) => state, |
|
2065 * selectors: { |
|
2066 * getValue: ( state ) => state, |
|
2067 * }, |
|
2068 * } ); |
|
2069 * ``` |
|
2070 * |
|
2071 * @param {string} key Unique namespace identifier. |
|
2072 * @param {WPDataReduxStoreConfig} options Registered store options, with properties |
|
2073 * describing reducer, actions, selectors, |
|
2074 * and resolvers. |
|
2075 * |
|
2076 * @return {WPDataStore} Store Object. |
|
2077 */ |
|
2078 |
|
2079 |
|
2080 function createReduxStore(key, options) { |
|
2081 return { |
|
2082 name: key, |
|
2083 instantiate: registry => { |
|
2084 const reducer = options.reducer; |
|
2085 const thunkArgs = { |
|
2086 registry, |
|
2087 |
|
2088 get dispatch() { |
|
2089 return Object.assign(action => store.dispatch(action), getActions()); |
|
2090 }, |
|
2091 |
|
2092 get select() { |
|
2093 return Object.assign(selector => selector(store.__unstableOriginalGetState()), getSelectors()); |
|
2094 }, |
|
2095 |
|
2096 get resolveSelect() { |
|
2097 return getResolveSelectors(); |
|
2098 } |
|
2099 |
|
2100 }; |
|
2101 const store = instantiateReduxStore(key, options, registry, thunkArgs); |
|
2102 const resolversCache = createResolversCache(); |
|
2103 let resolvers; |
|
2104 const actions = mapActions({ ...actions_namespaceObject, |
|
2105 ...options.actions |
|
2106 }, store); |
|
2107 let selectors = mapSelectors({ ...Object(external_lodash_["mapValues"])(selectors_namespaceObject, selector => (state, ...args) => selector(state.metadata, ...args)), |
|
2108 ...Object(external_lodash_["mapValues"])(options.selectors, selector => { |
|
2109 if (selector.isRegistrySelector) { |
|
2110 selector.registry = registry; |
|
2111 } |
|
2112 |
|
2113 return (state, ...args) => selector(state.root, ...args); |
|
2114 }) |
|
2115 }, store); |
|
2116 |
|
2117 if (options.resolvers) { |
|
2118 const result = mapResolvers(options.resolvers, selectors, store, resolversCache); |
|
2119 resolvers = result.resolvers; |
|
2120 selectors = result.selectors; |
|
2121 } |
|
2122 |
|
2123 const resolveSelectors = mapResolveSelectors(selectors, store); |
|
2124 |
|
2125 const getSelectors = () => selectors; |
|
2126 |
|
2127 const getActions = () => actions; |
|
2128 |
|
2129 const getResolveSelectors = () => resolveSelectors; // We have some modules monkey-patching the store object |
|
2130 // It's wrong to do so but until we refactor all of our effects to controls |
|
2131 // We need to keep the same "store" instance here. |
|
2132 |
|
2133 |
|
2134 store.__unstableOriginalGetState = store.getState; |
|
2135 |
|
2136 store.getState = () => store.__unstableOriginalGetState().root; // Customize subscribe behavior to call listeners only on effective change, |
|
2137 // not on every dispatch. |
|
2138 |
|
2139 |
|
2140 const subscribe = store && (listener => { |
|
2141 let lastState = store.__unstableOriginalGetState(); |
|
2142 |
|
2143 return store.subscribe(() => { |
|
2144 const state = store.__unstableOriginalGetState(); |
|
2145 |
|
2146 const hasChanged = state !== lastState; |
|
2147 lastState = state; |
|
2148 |
|
2149 if (hasChanged) { |
|
2150 listener(); |
|
2151 } |
|
2152 }); |
|
2153 }); // This can be simplified to just { subscribe, getSelectors, getActions } |
|
2154 // Once we remove the use function. |
|
2155 |
|
2156 |
|
2157 return { |
|
2158 reducer, |
|
2159 store, |
|
2160 actions, |
|
2161 selectors, |
|
2162 resolvers, |
|
2163 getSelectors, |
|
2164 getResolveSelectors, |
|
2165 getActions, |
|
2166 subscribe |
|
2167 }; |
|
2168 } |
|
2169 }; |
|
2170 } |
|
2171 /** |
|
2172 * Creates a redux store for a namespace. |
1952 * |
2173 * |
1953 * @param {string} key Unique namespace identifier. |
2174 * @param {string} key Unique namespace identifier. |
1954 * @param {Object} options Registered store options, with properties |
2175 * @param {Object} options Registered store options, with properties |
1955 * describing reducer, actions, selectors, and |
2176 * describing reducer, actions, selectors, |
1956 * resolvers. |
2177 * and resolvers. |
1957 * @param {WPDataRegistry} registry Registry reference. |
2178 * @param {WPDataRegistry} registry Registry reference. |
1958 * |
2179 * @param {Object} thunkArgs Argument object for the thunk middleware. |
1959 * @return {Object} Store Object. |
2180 * @return {Object} Newly created redux store. |
1960 */ |
2181 */ |
1961 |
2182 |
1962 function createNamespace(key, options, registry) { |
2183 function instantiateReduxStore(key, options, registry, thunkArgs) { |
1963 var reducer = options.reducer; |
2184 const controls = { ...options.controls, |
1964 var store = createReduxStore(key, options, registry); |
2185 ...builtinControls |
1965 var resolvers; |
|
1966 var actions = mapActions(namespace_store_objectSpread({}, actions_namespaceObject, {}, options.actions), store); |
|
1967 var selectors = mapSelectors(namespace_store_objectSpread({}, Object(external_this_lodash_["mapValues"])(selectors_namespaceObject, function (selector) { |
|
1968 return function (state) { |
|
1969 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
|
1970 args[_key - 1] = arguments[_key]; |
|
1971 } |
|
1972 |
|
1973 return selector.apply(void 0, [state.metadata].concat(args)); |
|
1974 }; |
|
1975 }), {}, Object(external_this_lodash_["mapValues"])(options.selectors, function (selector) { |
|
1976 if (selector.isRegistrySelector) { |
|
1977 selector.registry = registry; |
|
1978 } |
|
1979 |
|
1980 return function (state) { |
|
1981 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
|
1982 args[_key2 - 1] = arguments[_key2]; |
|
1983 } |
|
1984 |
|
1985 return selector.apply(void 0, [state.root].concat(args)); |
|
1986 }; |
|
1987 })), store); |
|
1988 |
|
1989 if (options.resolvers) { |
|
1990 var result = mapResolvers(options.resolvers, selectors, store); |
|
1991 resolvers = result.resolvers; |
|
1992 selectors = result.selectors; |
|
1993 } |
|
1994 |
|
1995 var getSelectors = function getSelectors() { |
|
1996 return selectors; |
|
1997 }; |
2186 }; |
1998 |
2187 const normalizedControls = Object(external_lodash_["mapValues"])(controls, control => control.isRegistryControl ? control(registry) : control); |
1999 var getActions = function getActions() { |
2188 const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls)]; |
2000 return actions; |
2189 |
2001 }; // We have some modules monkey-patching the store object |
2190 if (options.__experimentalUseThunks) { |
2002 // It's wrong to do so but until we refactor all of our effects to controls |
2191 middlewares.push(createThunkMiddleware(thunkArgs)); |
2003 // We need to keep the same "store" instance here. |
2192 } |
2004 |
2193 |
2005 |
2194 const enhancers = [applyMiddleware(...middlewares)]; |
2006 store.__unstableOriginalGetState = store.getState; |
|
2007 |
|
2008 store.getState = function () { |
|
2009 return store.__unstableOriginalGetState().root; |
|
2010 }; // Customize subscribe behavior to call listeners only on effective change, |
|
2011 // not on every dispatch. |
|
2012 |
|
2013 |
|
2014 var subscribe = store && function (listener) { |
|
2015 var lastState = store.__unstableOriginalGetState(); |
|
2016 |
|
2017 store.subscribe(function () { |
|
2018 var state = store.__unstableOriginalGetState(); |
|
2019 |
|
2020 var hasChanged = state !== lastState; |
|
2021 lastState = state; |
|
2022 |
|
2023 if (hasChanged) { |
|
2024 listener(); |
|
2025 } |
|
2026 }); |
|
2027 }; // This can be simplified to just { subscribe, getSelectors, getActions } |
|
2028 // Once we remove the use function. |
|
2029 |
|
2030 |
|
2031 return { |
|
2032 reducer: reducer, |
|
2033 store: store, |
|
2034 actions: actions, |
|
2035 selectors: selectors, |
|
2036 resolvers: resolvers, |
|
2037 getSelectors: getSelectors, |
|
2038 getActions: getActions, |
|
2039 subscribe: subscribe |
|
2040 }; |
|
2041 } |
|
2042 /** |
|
2043 * Creates a redux store for a namespace. |
|
2044 * |
|
2045 * @param {string} key Unique namespace identifier. |
|
2046 * @param {Object} options Registered store options, with properties |
|
2047 * describing reducer, actions, selectors, and |
|
2048 * resolvers. |
|
2049 * @param {WPDataRegistry} registry Registry reference. |
|
2050 * |
|
2051 * @return {Object} Newly created redux store. |
|
2052 */ |
|
2053 |
|
2054 function createReduxStore(key, options, registry) { |
|
2055 var middlewares = [resolvers_cache_middleware(registry, key), promise_middleware]; |
|
2056 |
|
2057 if (options.controls) { |
|
2058 var normalizedControls = Object(external_this_lodash_["mapValues"])(options.controls, function (control) { |
|
2059 return control.isRegistryControl ? control(registry) : control; |
|
2060 }); |
|
2061 middlewares.push(external_this_wp_reduxRoutine_default()(normalizedControls)); |
|
2062 } |
|
2063 |
|
2064 var enhancers = [applyMiddleware.apply(void 0, middlewares)]; |
|
2065 |
2195 |
2066 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
2196 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
2067 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
2197 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
2068 name: key, |
2198 name: key, |
2069 instanceId: key |
2199 instanceId: key |
2070 })); |
2200 })); |
2071 } |
2201 } |
2072 |
2202 |
2073 var reducer = options.reducer, |
2203 const { |
2074 initialState = options.initialState; |
2204 reducer, |
2075 var enhancedReducer = turbo_combine_reducers_default()({ |
2205 initialState |
|
2206 } = options; |
|
2207 const enhancedReducer = turbo_combine_reducers_default()({ |
2076 metadata: metadata_reducer, |
2208 metadata: metadata_reducer, |
2077 root: reducer |
2209 root: reducer |
2078 }); |
2210 }); |
2079 return createStore(enhancedReducer, { |
2211 return redux_createStore(enhancedReducer, { |
2080 root: initialState |
2212 root: initialState |
2081 }, Object(external_this_lodash_["flowRight"])(enhancers)); |
2213 }, Object(external_lodash_["flowRight"])(enhancers)); |
2082 } |
2214 } |
2083 /** |
2215 /** |
2084 * Maps selectors to a store. |
2216 * Maps selectors to a store. |
2085 * |
2217 * |
2086 * @param {Object} selectors Selectors to register. Keys will be used as the |
2218 * @param {Object} selectors Selectors to register. Keys will be used as the |
2087 * public facing API. Selectors will get passed the |
2219 * public facing API. Selectors will get passed the |
2088 * state as first argument. |
2220 * state as first argument. |
2089 * @param {Object} store The store to which the selectors should be mapped. |
2221 * @param {Object} store The store to which the selectors should be mapped. |
2090 * |
|
2091 * @return {Object} Selectors mapped to the provided store. |
2222 * @return {Object} Selectors mapped to the provided store. |
2092 */ |
2223 */ |
2093 |
2224 |
2094 |
2225 |
2095 function mapSelectors(selectors, store) { |
2226 function mapSelectors(selectors, store) { |
2096 var createStateSelector = function createStateSelector(registrySelector) { |
2227 const createStateSelector = registrySelector => { |
2097 var selector = function runSelector() { |
2228 const selector = function runSelector() { |
2098 // This function is an optimized implementation of: |
2229 // This function is an optimized implementation of: |
2099 // |
2230 // |
2100 // selector( store.getState(), ...arguments ) |
2231 // selector( store.getState(), ...arguments ) |
2101 // |
2232 // |
2102 // Where the above would incur an `Array#concat` in its application, |
2233 // Where the above would incur an `Array#concat` in its application, |
2103 // the logic here instead efficiently constructs an arguments array via |
2234 // the logic here instead efficiently constructs an arguments array via |
2104 // direct assignment. |
2235 // direct assignment. |
2105 var argsLength = arguments.length; |
2236 const argsLength = arguments.length; |
2106 var args = new Array(argsLength + 1); |
2237 const args = new Array(argsLength + 1); |
2107 args[0] = store.__unstableOriginalGetState(); |
2238 args[0] = store.__unstableOriginalGetState(); |
2108 |
2239 |
2109 for (var i = 0; i < argsLength; i++) { |
2240 for (let i = 0; i < argsLength; i++) { |
2110 args[i + 1] = arguments[i]; |
2241 args[i + 1] = arguments[i]; |
2111 } |
2242 } |
2112 |
2243 |
2113 return registrySelector.apply(void 0, args); |
2244 return registrySelector(...args); |
2114 }; |
2245 }; |
2115 |
2246 |
2116 selector.hasResolver = false; |
2247 selector.hasResolver = false; |
2117 return selector; |
2248 return selector; |
2118 }; |
2249 }; |
2119 |
2250 |
2120 return Object(external_this_lodash_["mapValues"])(selectors, createStateSelector); |
2251 return Object(external_lodash_["mapValues"])(selectors, createStateSelector); |
2121 } |
2252 } |
2122 /** |
2253 /** |
2123 * Maps actions to dispatch from a given store. |
2254 * Maps actions to dispatch from a given store. |
2124 * |
2255 * |
2125 * @param {Object} actions Actions to register. |
2256 * @param {Object} actions Actions to register. |
2127 * @return {Object} Actions mapped to the redux store provided. |
2258 * @return {Object} Actions mapped to the redux store provided. |
2128 */ |
2259 */ |
2129 |
2260 |
2130 |
2261 |
2131 function mapActions(actions, store) { |
2262 function mapActions(actions, store) { |
2132 var createBoundAction = function createBoundAction(action) { |
2263 const createBoundAction = action => (...args) => { |
2133 return function () { |
2264 return Promise.resolve(store.dispatch(action(...args))); |
2134 return Promise.resolve(store.dispatch(action.apply(void 0, arguments))); |
|
2135 }; |
|
2136 }; |
2265 }; |
2137 |
2266 |
2138 return Object(external_this_lodash_["mapValues"])(actions, createBoundAction); |
2267 return Object(external_lodash_["mapValues"])(actions, createBoundAction); |
|
2268 } |
|
2269 /** |
|
2270 * Maps selectors to functions that return a resolution promise for them |
|
2271 * |
|
2272 * @param {Object} selectors Selectors to map. |
|
2273 * @param {Object} store The redux store the selectors select from. |
|
2274 * @return {Object} Selectors mapped to their resolution functions. |
|
2275 */ |
|
2276 |
|
2277 |
|
2278 function mapResolveSelectors(selectors, store) { |
|
2279 return Object(external_lodash_["mapValues"])(Object(external_lodash_["omit"])(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']), (selector, selectorName) => (...args) => new Promise(resolve => { |
|
2280 const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); |
|
2281 |
|
2282 const getResult = () => selector.apply(null, args); // trigger the selector (to trigger the resolver) |
|
2283 |
|
2284 |
|
2285 const result = getResult(); |
|
2286 |
|
2287 if (hasFinished()) { |
|
2288 return resolve(result); |
|
2289 } |
|
2290 |
|
2291 const unsubscribe = store.subscribe(() => { |
|
2292 if (hasFinished()) { |
|
2293 unsubscribe(); |
|
2294 resolve(getResult()); |
|
2295 } |
|
2296 }); |
|
2297 })); |
2139 } |
2298 } |
2140 /** |
2299 /** |
2141 * Returns resolvers with matched selectors for a given namespace. |
2300 * Returns resolvers with matched selectors for a given namespace. |
2142 * Resolvers are side effects invoked once per argument set of a given selector call, |
2301 * Resolvers are side effects invoked once per argument set of a given selector call, |
2143 * used in ensuring that the data needs for the selector are satisfied. |
2302 * used in ensuring that the data needs for the selector are satisfied. |
2144 * |
2303 * |
2145 * @param {Object} resolvers Resolvers to register. |
2304 * @param {Object} resolvers Resolvers to register. |
2146 * @param {Object} selectors The current selectors to be modified. |
2305 * @param {Object} selectors The current selectors to be modified. |
2147 * @param {Object} store The redux store to which the resolvers should be mapped. |
2306 * @param {Object} store The redux store to which the resolvers should be mapped. |
2148 * @return {Object} An object containing updated selectors and resolvers. |
2307 * @param {Object} resolversCache Resolvers Cache. |
2149 */ |
2308 */ |
2150 |
2309 |
2151 |
2310 |
2152 function mapResolvers(resolvers, selectors, store) { |
2311 function mapResolvers(resolvers, selectors, store, resolversCache) { |
2153 var mappedResolvers = Object(external_this_lodash_["mapValues"])(resolvers, function (resolver) { |
2312 // The `resolver` can be either a function that does the resolution, or, in more advanced |
2154 var _resolver$fulfill = resolver.fulfill, |
2313 // cases, an object with a `fullfill` method and other optional methods like `isFulfilled`. |
2155 resolverFulfill = _resolver$fulfill === void 0 ? resolver : _resolver$fulfill; |
2314 // Here we normalize the `resolver` function to an object with `fulfill` method. |
2156 return namespace_store_objectSpread({}, resolver, { |
2315 const mappedResolvers = Object(external_lodash_["mapValues"])(resolvers, resolver => { |
2157 fulfill: resolverFulfill |
2316 if (resolver.fulfill) { |
2158 }); |
2317 return resolver; |
|
2318 } |
|
2319 |
|
2320 return { ...resolver, |
|
2321 // copy the enumerable properties of the resolver function |
|
2322 fulfill: resolver // add the fulfill method |
|
2323 |
|
2324 }; |
2159 }); |
2325 }); |
2160 |
2326 |
2161 var mapSelector = function mapSelector(selector, selectorName) { |
2327 const mapSelector = (selector, selectorName) => { |
2162 var resolver = resolvers[selectorName]; |
2328 const resolver = resolvers[selectorName]; |
2163 |
2329 |
2164 if (!resolver) { |
2330 if (!resolver) { |
2165 selector.hasResolver = false; |
2331 selector.hasResolver = false; |
2166 return selector; |
2332 return selector; |
2167 } |
2333 } |
2168 |
2334 |
2169 var selectorResolver = function selectorResolver() { |
2335 const selectorResolver = (...args) => { |
2170 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { |
2336 async function fulfillSelector() { |
2171 args[_key3] = arguments[_key3]; |
2337 const state = store.getState(); |
|
2338 |
|
2339 if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { |
|
2340 return; |
|
2341 } |
|
2342 |
|
2343 const { |
|
2344 metadata |
|
2345 } = store.__unstableOriginalGetState(); |
|
2346 |
|
2347 if (hasStartedResolution(metadata, selectorName, args)) { |
|
2348 return; |
|
2349 } |
|
2350 |
|
2351 resolversCache.markAsRunning(selectorName, args); |
|
2352 setTimeout(async () => { |
|
2353 resolversCache.clear(selectorName, args); |
|
2354 store.dispatch(startResolution(selectorName, args)); |
|
2355 await fulfillResolver(store, mappedResolvers, selectorName, ...args); |
|
2356 store.dispatch(finishResolution(selectorName, args)); |
|
2357 }); |
2172 } |
2358 } |
2173 |
2359 |
2174 function fulfillSelector() { |
2360 fulfillSelector(...args); |
2175 return _fulfillSelector.apply(this, arguments); |
2361 return selector(...args); |
2176 } |
|
2177 |
|
2178 function _fulfillSelector() { |
|
2179 _fulfillSelector = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee() { |
|
2180 var state, _store$__unstableOrig, metadata; |
|
2181 |
|
2182 return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) { |
|
2183 while (1) { |
|
2184 switch (_context.prev = _context.next) { |
|
2185 case 0: |
|
2186 state = store.getState(); |
|
2187 |
|
2188 if (!(typeof resolver.isFulfilled === 'function' && resolver.isFulfilled.apply(resolver, [state].concat(args)))) { |
|
2189 _context.next = 3; |
|
2190 break; |
|
2191 } |
|
2192 |
|
2193 return _context.abrupt("return"); |
|
2194 |
|
2195 case 3: |
|
2196 _store$__unstableOrig = store.__unstableOriginalGetState(), metadata = _store$__unstableOrig.metadata; |
|
2197 |
|
2198 if (!hasStartedResolution(metadata, selectorName, args)) { |
|
2199 _context.next = 6; |
|
2200 break; |
|
2201 } |
|
2202 |
|
2203 return _context.abrupt("return"); |
|
2204 |
|
2205 case 6: |
|
2206 store.dispatch(startResolution(selectorName, args)); |
|
2207 _context.next = 9; |
|
2208 return fulfillResolver.apply(void 0, [store, mappedResolvers, selectorName].concat(args)); |
|
2209 |
|
2210 case 9: |
|
2211 store.dispatch(finishResolution(selectorName, args)); |
|
2212 |
|
2213 case 10: |
|
2214 case "end": |
|
2215 return _context.stop(); |
|
2216 } |
|
2217 } |
|
2218 }, _callee); |
|
2219 })); |
|
2220 return _fulfillSelector.apply(this, arguments); |
|
2221 } |
|
2222 |
|
2223 fulfillSelector.apply(void 0, args); |
|
2224 return selector.apply(void 0, args); |
|
2225 }; |
2362 }; |
2226 |
2363 |
2227 selectorResolver.hasResolver = true; |
2364 selectorResolver.hasResolver = true; |
2228 return selectorResolver; |
2365 return selectorResolver; |
2229 }; |
2366 }; |
2230 |
2367 |
2231 return { |
2368 return { |
2232 resolvers: mappedResolvers, |
2369 resolvers: mappedResolvers, |
2233 selectors: Object(external_this_lodash_["mapValues"])(selectors, mapSelector) |
2370 selectors: Object(external_lodash_["mapValues"])(selectors, mapSelector) |
2234 }; |
2371 }; |
2235 } |
2372 } |
2236 /** |
2373 /** |
2237 * Calls a resolver given arguments |
2374 * Calls a resolver given arguments |
2238 * |
2375 * |
2241 * @param {string} selectorName Selector name to fulfill. |
2378 * @param {string} selectorName Selector name to fulfill. |
2242 * @param {Array} args Selector Arguments. |
2379 * @param {Array} args Selector Arguments. |
2243 */ |
2380 */ |
2244 |
2381 |
2245 |
2382 |
2246 function fulfillResolver(_x, _x2, _x3) { |
2383 async function fulfillResolver(store, resolvers, selectorName, ...args) { |
2247 return _fulfillResolver.apply(this, arguments); |
2384 const resolver = Object(external_lodash_["get"])(resolvers, [selectorName]); |
2248 } |
2385 |
2249 |
2386 if (!resolver) { |
2250 function _fulfillResolver() { |
2387 return; |
2251 _fulfillResolver = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee2(store, resolvers, selectorName) { |
2388 } |
2252 var resolver, |
2389 |
2253 _len4, |
2390 const action = resolver.fulfill(...args); |
2254 args, |
2391 |
2255 _key4, |
2392 if (action) { |
2256 action, |
2393 await store.dispatch(action); |
2257 _args2 = arguments; |
2394 } |
2258 |
|
2259 return external_this_regeneratorRuntime_default.a.wrap(function _callee2$(_context2) { |
|
2260 while (1) { |
|
2261 switch (_context2.prev = _context2.next) { |
|
2262 case 0: |
|
2263 resolver = Object(external_this_lodash_["get"])(resolvers, [selectorName]); |
|
2264 |
|
2265 if (resolver) { |
|
2266 _context2.next = 3; |
|
2267 break; |
|
2268 } |
|
2269 |
|
2270 return _context2.abrupt("return"); |
|
2271 |
|
2272 case 3: |
|
2273 for (_len4 = _args2.length, args = new Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) { |
|
2274 args[_key4 - 3] = _args2[_key4]; |
|
2275 } |
|
2276 |
|
2277 action = resolver.fulfill.apply(resolver, args); |
|
2278 |
|
2279 if (!action) { |
|
2280 _context2.next = 8; |
|
2281 break; |
|
2282 } |
|
2283 |
|
2284 _context2.next = 8; |
|
2285 return store.dispatch(action); |
|
2286 |
|
2287 case 8: |
|
2288 case "end": |
|
2289 return _context2.stop(); |
|
2290 } |
|
2291 } |
|
2292 }, _callee2); |
|
2293 })); |
|
2294 return _fulfillResolver.apply(this, arguments); |
|
2295 } |
2395 } |
2296 |
2396 |
2297 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/store/index.js |
2397 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/store/index.js |
2298 |
|
2299 |
|
2300 function store_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
2301 |
|
2302 function store_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { store_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { store_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
2303 |
|
2304 function createCoreDataStore(registry) { |
2398 function createCoreDataStore(registry) { |
2305 var getCoreDataSelector = function getCoreDataSelector(selectorName) { |
2399 const getCoreDataSelector = selectorName => (key, ...args) => { |
2306 return function (reducerKey) { |
2400 return registry.select(key)[selectorName](...args); |
2307 var _registry$select; |
|
2308 |
|
2309 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
|
2310 args[_key - 1] = arguments[_key]; |
|
2311 } |
|
2312 |
|
2313 return (_registry$select = registry.select(reducerKey))[selectorName].apply(_registry$select, args); |
|
2314 }; |
|
2315 }; |
2401 }; |
2316 |
2402 |
2317 var getCoreDataAction = function getCoreDataAction(actionName) { |
2403 const getCoreDataAction = actionName => (key, ...args) => { |
2318 return function (reducerKey) { |
2404 return registry.dispatch(key)[actionName](...args); |
2319 var _registry$dispatch; |
|
2320 |
|
2321 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
|
2322 args[_key2 - 1] = arguments[_key2]; |
|
2323 } |
|
2324 |
|
2325 return (_registry$dispatch = registry.dispatch(reducerKey))[actionName].apply(_registry$dispatch, args); |
|
2326 }; |
|
2327 }; |
2405 }; |
2328 |
2406 |
2329 return { |
2407 return { |
2330 getSelectors: function getSelectors() { |
2408 getSelectors() { |
2331 return ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].reduce(function (memo, selectorName) { |
2409 return ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].reduce((memo, selectorName) => ({ ...memo, |
2332 return store_objectSpread({}, memo, Object(defineProperty["a" /* default */])({}, selectorName, getCoreDataSelector(selectorName))); |
2410 [selectorName]: getCoreDataSelector(selectorName) |
2333 }, {}); |
2411 }), {}); |
2334 }, |
2412 }, |
2335 getActions: function getActions() { |
2413 |
2336 return ['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].reduce(function (memo, actionName) { |
2414 getActions() { |
2337 return store_objectSpread({}, memo, Object(defineProperty["a" /* default */])({}, actionName, getCoreDataAction(actionName))); |
2415 return ['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].reduce((memo, actionName) => ({ ...memo, |
2338 }, {}); |
2416 [actionName]: getCoreDataAction(actionName) |
|
2417 }), {}); |
2339 }, |
2418 }, |
2340 subscribe: function subscribe() { |
2419 |
|
2420 subscribe() { |
2341 // There's no reasons to trigger any listener when we subscribe to this store |
2421 // There's no reasons to trigger any listener when we subscribe to this store |
2342 // because there's no state stored in this store that need to retrigger selectors |
2422 // because there's no state stored in this store that need to retrigger selectors |
2343 // if a change happens, the corresponding store where the tracking stated live |
2423 // if a change happens, the corresponding store where the tracking stated live |
2344 // would have already triggered a "subscribe" call. |
2424 // would have already triggered a "subscribe" call. |
2345 return function () {}; |
2425 return () => {}; |
2346 } |
2426 } |
|
2427 |
2347 }; |
2428 }; |
2348 } |
2429 } |
2349 |
2430 |
2350 /* harmony default export */ var build_module_store = (createCoreDataStore); |
2431 /* harmony default export */ var build_module_store = (createCoreDataStore); |
2351 |
2432 |
2352 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/registry.js |
2433 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/registry.js |
2353 |
|
2354 |
|
2355 |
|
2356 function registry_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
2357 |
|
2358 function registry_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { registry_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { registry_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
2359 |
|
2360 /** |
2434 /** |
2361 * External dependencies |
2435 * External dependencies |
2362 */ |
2436 */ |
2363 |
2437 |
2364 |
|
2365 /** |
2438 /** |
2366 * Internal dependencies |
2439 * Internal dependencies |
2367 */ |
2440 */ |
2368 |
2441 |
2369 |
2442 |
|
2443 |
|
2444 /** @typedef {import('./types').WPDataStore} WPDataStore */ |
2370 |
2445 |
2371 /** |
2446 /** |
2372 * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. |
2447 * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. |
2373 * |
2448 * |
2374 * @property {Function} registerGenericStore Given a namespace key and settings |
2449 * @property {Function} registerGenericStore Given a namespace key and settings |
2402 * @param {Object?} parent Parent registry. |
2477 * @param {Object?} parent Parent registry. |
2403 * |
2478 * |
2404 * @return {WPDataRegistry} Data registry. |
2479 * @return {WPDataRegistry} Data registry. |
2405 */ |
2480 */ |
2406 |
2481 |
2407 function createRegistry() { |
2482 function createRegistry(storeConfigs = {}, parent = null) { |
2408 var storeConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
2483 const stores = {}; |
2409 var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
2484 let listeners = []; |
2410 var stores = {}; |
2485 |
2411 var listeners = []; |
2486 const __experimentalListeningStores = new Set(); |
2412 /** |
2487 /** |
2413 * Global listener called for each store's update. |
2488 * Global listener called for each store's update. |
2414 */ |
2489 */ |
2415 |
2490 |
|
2491 |
2416 function globalListener() { |
2492 function globalListener() { |
2417 listeners.forEach(function (listener) { |
2493 listeners.forEach(listener => listener()); |
2418 return listener(); |
|
2419 }); |
|
2420 } |
2494 } |
2421 /** |
2495 /** |
2422 * Subscribe to changes to any data. |
2496 * Subscribe to changes to any data. |
2423 * |
2497 * |
2424 * @param {Function} listener Listener function. |
2498 * @param {Function} listener Listener function. |
2425 * |
2499 * |
2426 * @return {Function} Unsubscribe function. |
2500 * @return {Function} Unsubscribe function. |
2427 */ |
2501 */ |
2428 |
2502 |
2429 |
2503 |
2430 var subscribe = function subscribe(listener) { |
2504 const subscribe = listener => { |
2431 listeners.push(listener); |
2505 listeners.push(listener); |
2432 return function () { |
2506 return () => { |
2433 listeners = Object(external_this_lodash_["without"])(listeners, listener); |
2507 listeners = Object(external_lodash_["without"])(listeners, listener); |
2434 }; |
2508 }; |
2435 }; |
2509 }; |
2436 /** |
2510 /** |
2437 * Calls a selector given the current state and extra arguments. |
2511 * Calls a selector given the current state and extra arguments. |
2438 * |
2512 * |
2439 * @param {string} reducerKey Part of the state shape to register the |
2513 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
2440 * selectors for. |
2514 * or the store definition. |
2441 * |
2515 * |
2442 * @return {*} The selector's returned value. |
2516 * @return {*} The selector's returned value. |
2443 */ |
2517 */ |
2444 |
2518 |
2445 |
2519 |
2446 function select(reducerKey) { |
2520 function select(storeNameOrDefinition) { |
2447 var store = stores[reducerKey]; |
2521 const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
|
2522 |
|
2523 __experimentalListeningStores.add(storeName); |
|
2524 |
|
2525 const store = stores[storeName]; |
2448 |
2526 |
2449 if (store) { |
2527 if (store) { |
2450 return store.getSelectors(); |
2528 return store.getSelectors(); |
2451 } |
2529 } |
2452 |
2530 |
2453 return parent && parent.select(reducerKey); |
2531 return parent && parent.select(storeName); |
2454 } |
2532 } |
2455 |
2533 |
2456 var getResolveSelectors = memize_default()(function (selectors) { |
2534 function __experimentalMarkListeningStores(callback, ref) { |
2457 return Object(external_this_lodash_["mapValues"])(Object(external_this_lodash_["omit"])(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']), function (selector, selectorName) { |
2535 __experimentalListeningStores.clear(); |
2458 return function () { |
2536 |
2459 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
2537 const result = callback.call(this); |
2460 args[_key] = arguments[_key]; |
2538 ref.current = Array.from(__experimentalListeningStores); |
2461 } |
2539 return result; |
2462 |
2540 } |
2463 return new Promise(function (resolve) { |
|
2464 var hasFinished = function hasFinished() { |
|
2465 return selectors.hasFinishedResolution(selectorName, args); |
|
2466 }; |
|
2467 |
|
2468 var getResult = function getResult() { |
|
2469 return selector.apply(null, args); |
|
2470 }; // trigger the selector (to trigger the resolver) |
|
2471 |
|
2472 |
|
2473 var result = getResult(); |
|
2474 |
|
2475 if (hasFinished()) { |
|
2476 return resolve(result); |
|
2477 } |
|
2478 |
|
2479 var unsubscribe = subscribe(function () { |
|
2480 if (hasFinished()) { |
|
2481 unsubscribe(); |
|
2482 resolve(getResult()); |
|
2483 } |
|
2484 }); |
|
2485 }); |
|
2486 }; |
|
2487 }); |
|
2488 }, { |
|
2489 maxSize: 1 |
|
2490 }); |
|
2491 /** |
2541 /** |
2492 * Given the name of a registered store, returns an object containing the store's |
2542 * Given the name of a registered store, returns an object containing the store's |
2493 * selectors pre-bound to state so that you only need to supply additional arguments, |
2543 * selectors pre-bound to state so that you only need to supply additional arguments, |
2494 * and modified so that they return promises that resolve to their eventual values, |
2544 * and modified so that they return promises that resolve to their eventual values, |
2495 * after any resolvers have ran. |
2545 * after any resolvers have ran. |
2496 * |
2546 * |
2497 * @param {string} reducerKey Part of the state shape to register the |
2547 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
2498 * selectors for. |
2548 * or the store definition. |
2499 * |
2549 * |
2500 * @return {Object} Each key of the object matches the name of a selector. |
2550 * @return {Object} Each key of the object matches the name of a selector. |
2501 */ |
2551 */ |
2502 |
2552 |
2503 function __experimentalResolveSelect(reducerKey) { |
2553 |
2504 return getResolveSelectors(select(reducerKey)); |
2554 function resolveSelect(storeNameOrDefinition) { |
|
2555 const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
|
2556 |
|
2557 __experimentalListeningStores.add(storeName); |
|
2558 |
|
2559 const store = stores[storeName]; |
|
2560 |
|
2561 if (store) { |
|
2562 return store.getResolveSelectors(); |
|
2563 } |
|
2564 |
|
2565 return parent && parent.resolveSelect(storeName); |
2505 } |
2566 } |
2506 /** |
2567 /** |
2507 * Returns the available actions for a part of the state. |
2568 * Returns the available actions for a part of the state. |
2508 * |
2569 * |
2509 * @param {string} reducerKey Part of the state shape to dispatch the |
2570 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
2510 * action for. |
2571 * or the store definition. |
2511 * |
2572 * |
2512 * @return {*} The action's returned value. |
2573 * @return {*} The action's returned value. |
2513 */ |
2574 */ |
2514 |
2575 |
2515 |
2576 |
2516 function dispatch(reducerKey) { |
2577 function dispatch(storeNameOrDefinition) { |
2517 var store = stores[reducerKey]; |
2578 const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
|
2579 const store = stores[storeName]; |
2518 |
2580 |
2519 if (store) { |
2581 if (store) { |
2520 return store.getActions(); |
2582 return store.getActions(); |
2521 } |
2583 } |
2522 |
2584 |
2523 return parent && parent.dispatch(reducerKey); |
2585 return parent && parent.dispatch(storeName); |
2524 } // |
2586 } // |
2525 // Deprecated |
2587 // Deprecated |
2526 // TODO: Remove this after `use()` is removed. |
2588 // TODO: Remove this after `use()` is removed. |
2527 // |
2589 // |
2528 |
2590 |
2529 |
2591 |
2530 function withPlugins(attributes) { |
2592 function withPlugins(attributes) { |
2531 return Object(external_this_lodash_["mapValues"])(attributes, function (attribute, key) { |
2593 return Object(external_lodash_["mapValues"])(attributes, (attribute, key) => { |
2532 if (typeof attribute !== 'function') { |
2594 if (typeof attribute !== 'function') { |
2533 return attribute; |
2595 return attribute; |
2534 } |
2596 } |
2535 |
2597 |
2536 return function () { |
2598 return function () { |
2560 } |
2622 } |
2561 |
2623 |
2562 stores[key] = config; |
2624 stores[key] = config; |
2563 config.subscribe(globalListener); |
2625 config.subscribe(globalListener); |
2564 } |
2626 } |
2565 |
2627 /** |
2566 var registry = { |
2628 * Registers a new store definition. |
2567 registerGenericStore: registerGenericStore, |
2629 * |
2568 stores: stores, |
2630 * @param {WPDataStore} store Store definition. |
|
2631 */ |
|
2632 |
|
2633 |
|
2634 function register(store) { |
|
2635 registerGenericStore(store.name, store.instantiate(registry)); |
|
2636 } |
|
2637 /** |
|
2638 * Subscribe handler to a store. |
|
2639 * |
|
2640 * @param {string[]} storeName The store name. |
|
2641 * @param {Function} handler The function subscribed to the store. |
|
2642 * @return {Function} A function to unsubscribe the handler. |
|
2643 */ |
|
2644 |
|
2645 |
|
2646 function __experimentalSubscribeStore(storeName, handler) { |
|
2647 if (storeName in stores) { |
|
2648 return stores[storeName].subscribe(handler); |
|
2649 } // Trying to access a store that hasn't been registered, |
|
2650 // this is a pattern rarely used but seen in some places. |
|
2651 // We fallback to regular `subscribe` here for backward-compatibility for now. |
|
2652 // See https://github.com/WordPress/gutenberg/pull/27466 for more info. |
|
2653 |
|
2654 |
|
2655 if (!parent) { |
|
2656 return subscribe(handler); |
|
2657 } |
|
2658 |
|
2659 return parent.__experimentalSubscribeStore(storeName, handler); |
|
2660 } |
|
2661 |
|
2662 let registry = { |
|
2663 registerGenericStore, |
|
2664 stores, |
2569 namespaces: stores, |
2665 namespaces: stores, |
2570 // TODO: Deprecate/remove this. |
2666 // TODO: Deprecate/remove this. |
2571 subscribe: subscribe, |
2667 subscribe, |
2572 select: select, |
2668 select, |
2573 __experimentalResolveSelect: __experimentalResolveSelect, |
2669 resolveSelect, |
2574 dispatch: dispatch, |
2670 dispatch, |
2575 use: use |
2671 use, |
|
2672 register, |
|
2673 __experimentalMarkListeningStores, |
|
2674 __experimentalSubscribeStore |
2576 }; |
2675 }; |
2577 /** |
2676 /** |
2578 * Registers a standard `@wordpress/data` store. |
2677 * Registers a standard `@wordpress/data` store. |
2579 * |
2678 * |
2580 * @param {string} reducerKey Reducer key. |
2679 * @param {string} storeName Unique namespace identifier. |
2581 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
2680 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
2582 * |
2681 * |
2583 * @return {Object} Registered store object. |
2682 * @return {Object} Registered store object. |
2584 */ |
2683 */ |
2585 |
2684 |
2586 registry.registerStore = function (reducerKey, options) { |
2685 registry.registerStore = (storeName, options) => { |
2587 if (!options.reducer) { |
2686 if (!options.reducer) { |
2588 throw new TypeError('Must specify store reducer'); |
2687 throw new TypeError('Must specify store reducer'); |
2589 } |
2688 } |
2590 |
2689 |
2591 var namespace = createNamespace(reducerKey, options, registry); |
2690 const store = createReduxStore(storeName, options).instantiate(registry); |
2592 registerGenericStore(reducerKey, namespace); |
2691 registerGenericStore(storeName, store); |
2593 return namespace.store; |
2692 return store.store; |
2594 }; // |
2693 }; // |
2595 // TODO: |
2694 // TODO: |
2596 // This function will be deprecated as soon as it is no longer internally referenced. |
2695 // This function will be deprecated as soon as it is no longer internally referenced. |
2597 // |
2696 // |
2598 |
2697 |
2599 |
2698 |
2600 function use(plugin, options) { |
2699 function use(plugin, options) { |
2601 registry = registry_objectSpread({}, registry, {}, plugin(registry, options)); |
2700 registry = { ...registry, |
|
2701 ...plugin(registry, options) |
|
2702 }; |
2602 return registry; |
2703 return registry; |
2603 } |
2704 } |
2604 |
2705 |
2605 registerGenericStore('core/data', build_module_store(registry)); |
2706 registerGenericStore('core/data', build_module_store(registry)); |
2606 Object.entries(storeConfigs).forEach(function (_ref) { |
2707 Object.entries(storeConfigs).forEach(([name, config]) => registry.registerStore(name, config)); |
2607 var _ref2 = Object(slicedToArray["a" /* default */])(_ref, 2), |
|
2608 name = _ref2[0], |
|
2609 config = _ref2[1]; |
|
2610 |
|
2611 return registry.registerStore(name, config); |
|
2612 }); |
|
2613 |
2708 |
2614 if (parent) { |
2709 if (parent) { |
2615 parent.subscribe(globalListener); |
2710 parent.subscribe(globalListener); |
2616 } |
2711 } |
2617 |
2712 |
2623 * Internal dependencies |
2718 * Internal dependencies |
2624 */ |
2719 */ |
2625 |
2720 |
2626 /* harmony default export */ var default_registry = (createRegistry()); |
2721 /* harmony default export */ var default_registry = (createRegistry()); |
2627 |
2722 |
2628 // EXTERNAL MODULE: external {"this":["wp","deprecated"]} |
2723 // EXTERNAL MODULE: external ["wp","deprecated"] |
2629 var external_this_wp_deprecated_ = __webpack_require__(37); |
2724 var external_wp_deprecated_ = __webpack_require__("NMb1"); |
2630 var external_this_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_deprecated_); |
2725 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_); |
2631 |
2726 |
2632 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/controls/index.js |
2727 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/controls/index.js |
2633 /** |
2728 /** |
2634 * WordPress dependencies |
2729 * WordPress dependencies |
2635 */ |
2730 */ |
2636 |
2731 |
2637 /* harmony default export */ var controls = (function (registry) { |
2732 /* harmony default export */ var plugins_controls = (registry => { |
2638 external_this_wp_deprecated_default()('wp.data.plugins.controls', { |
2733 external_wp_deprecated_default()('wp.data.plugins.controls', { |
|
2734 since: '5.4', |
2639 hint: 'The controls plugins is now baked-in.' |
2735 hint: 'The controls plugins is now baked-in.' |
2640 }); |
2736 }); |
2641 return registry; |
2737 return registry; |
2642 }); |
2738 }); |
2643 |
2739 |
2644 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js |
2740 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js |
2645 var objectStorage; |
2741 let objectStorage; |
2646 var object_storage = { |
2742 const storage = { |
2647 getItem: function getItem(key) { |
2743 getItem(key) { |
2648 if (!objectStorage || !objectStorage[key]) { |
2744 if (!objectStorage || !objectStorage[key]) { |
2649 return null; |
2745 return null; |
2650 } |
2746 } |
2651 |
2747 |
2652 return objectStorage[key]; |
2748 return objectStorage[key]; |
2653 }, |
2749 }, |
2654 setItem: function setItem(key, value) { |
2750 |
|
2751 setItem(key, value) { |
2655 if (!objectStorage) { |
2752 if (!objectStorage) { |
2656 object_storage.clear(); |
2753 storage.clear(); |
2657 } |
2754 } |
2658 |
2755 |
2659 objectStorage[key] = String(value); |
2756 objectStorage[key] = String(value); |
2660 }, |
2757 }, |
2661 clear: function clear() { |
2758 |
|
2759 clear() { |
2662 objectStorage = Object.create(null); |
2760 objectStorage = Object.create(null); |
2663 } |
2761 } |
|
2762 |
2664 }; |
2763 }; |
2665 /* harmony default export */ var object = (object_storage); |
2764 /* harmony default export */ var object = (storage); |
2666 |
2765 |
2667 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js |
2766 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js |
2668 /** |
2767 /** |
2669 * Internal dependencies |
2768 * Internal dependencies |
2670 */ |
2769 */ |
2671 |
2770 |
2672 var default_storage; |
2771 let default_storage; |
2673 |
2772 |
2674 try { |
2773 try { |
2675 // Private Browsing in Safari 10 and earlier will throw an error when |
2774 // Private Browsing in Safari 10 and earlier will throw an error when |
2676 // attempting to set into localStorage. The test here is intentional in |
2775 // attempting to set into localStorage. The test here is intentional in |
2677 // causing a thrown error as condition for using fallback object storage. |
2776 // causing a thrown error as condition for using fallback object storage. |
2816 * |
2909 * |
2817 * @return {WPDataPlugin} Data plugin. |
2910 * @return {WPDataPlugin} Data plugin. |
2818 */ |
2911 */ |
2819 |
2912 |
2820 function persistencePlugin(registry, pluginOptions) { |
2913 function persistencePlugin(registry, pluginOptions) { |
2821 var persistence = createPersistenceInterface(pluginOptions); |
2914 const persistence = createPersistenceInterface(pluginOptions); |
2822 /** |
2915 /** |
2823 * Creates an enhanced store dispatch function, triggering the state of the |
2916 * Creates an enhanced store dispatch function, triggering the state of the |
2824 * given reducer key to be persisted when changed. |
2917 * given store name to be persisted when changed. |
2825 * |
2918 * |
2826 * @param {Function} getState Function which returns current state. |
2919 * @param {Function} getState Function which returns current state. |
2827 * @param {string} reducerKey Reducer key. |
2920 * @param {string} storeName Store name. |
2828 * @param {?Array<string>} keys Optional subset of keys to save. |
2921 * @param {?Array<string>} keys Optional subset of keys to save. |
2829 * |
2922 * |
2830 * @return {Function} Enhanced dispatch function. |
2923 * @return {Function} Enhanced dispatch function. |
2831 */ |
2924 */ |
2832 |
2925 |
2833 function createPersistOnChange(getState, reducerKey, keys) { |
2926 function createPersistOnChange(getState, storeName, keys) { |
2834 var getPersistedState; |
2927 let getPersistedState; |
2835 |
2928 |
2836 if (Array.isArray(keys)) { |
2929 if (Array.isArray(keys)) { |
2837 // Given keys, the persisted state should by produced as an object |
2930 // Given keys, the persisted state should by produced as an object |
2838 // of the subset of keys. This implementation uses combineReducers |
2931 // of the subset of keys. This implementation uses combineReducers |
2839 // to leverage its behavior of returning the same object when none |
2932 // to leverage its behavior of returning the same object when none |
2840 // of the property values changes. This allows a strict reference |
2933 // of the property values changes. This allows a strict reference |
2841 // equality to bypass a persistence set on an unchanging state. |
2934 // equality to bypass a persistence set on an unchanging state. |
2842 var reducers = keys.reduce(function (accumulator, key) { |
2935 const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { |
2843 return Object.assign(accumulator, Object(defineProperty["a" /* default */])({}, key, function (state, action) { |
2936 [key]: (state, action) => action.nextState[key] |
2844 return action.nextState[key]; |
2937 }), {}); |
2845 })); |
|
2846 }, {}); |
|
2847 getPersistedState = withLazySameState(turbo_combine_reducers_default()(reducers)); |
2938 getPersistedState = withLazySameState(turbo_combine_reducers_default()(reducers)); |
2848 } else { |
2939 } else { |
2849 getPersistedState = function getPersistedState(state, action) { |
2940 getPersistedState = (state, action) => action.nextState; |
2850 return action.nextState; |
2941 } |
2851 }; |
2942 |
2852 } |
2943 let lastState = getPersistedState(undefined, { |
2853 |
|
2854 var lastState = getPersistedState(undefined, { |
|
2855 nextState: getState() |
2944 nextState: getState() |
2856 }); |
2945 }); |
2857 return function () { |
2946 return () => { |
2858 var state = getPersistedState(lastState, { |
2947 const state = getPersistedState(lastState, { |
2859 nextState: getState() |
2948 nextState: getState() |
2860 }); |
2949 }); |
2861 |
2950 |
2862 if (state !== lastState) { |
2951 if (state !== lastState) { |
2863 persistence.set(reducerKey, state); |
2952 persistence.set(storeName, state); |
2864 lastState = state; |
2953 lastState = state; |
2865 } |
2954 } |
2866 }; |
2955 }; |
2867 } |
2956 } |
2868 |
2957 |
2869 return { |
2958 return { |
2870 registerStore: function registerStore(reducerKey, options) { |
2959 registerStore(storeName, options) { |
2871 if (!options.persist) { |
2960 if (!options.persist) { |
2872 return registry.registerStore(reducerKey, options); |
2961 return registry.registerStore(storeName, options); |
2873 } // Load from persistence to use as initial state. |
2962 } // Load from persistence to use as initial state. |
2874 |
2963 |
2875 |
2964 |
2876 var persistedState = persistence.get()[reducerKey]; |
2965 const persistedState = persistence.get()[storeName]; |
2877 |
2966 |
2878 if (persistedState !== undefined) { |
2967 if (persistedState !== undefined) { |
2879 var initialState = options.reducer(options.initialState, { |
2968 let initialState = options.reducer(options.initialState, { |
2880 type: '@@WP/PERSISTENCE_RESTORE' |
2969 type: '@@WP/PERSISTENCE_RESTORE' |
2881 }); |
2970 }); |
2882 |
2971 |
2883 if (Object(external_this_lodash_["isPlainObject"])(initialState) && Object(external_this_lodash_["isPlainObject"])(persistedState)) { |
2972 if (Object(external_lodash_["isPlainObject"])(initialState) && Object(external_lodash_["isPlainObject"])(persistedState)) { |
2884 // If state is an object, ensure that: |
2973 // If state is an object, ensure that: |
2885 // - Other keys are left intact when persisting only a |
2974 // - Other keys are left intact when persisting only a |
2886 // subset of keys. |
2975 // subset of keys. |
2887 // - New keys in what would otherwise be used as initial |
2976 // - New keys in what would otherwise be used as initial |
2888 // state are deeply merged as base for persisted value. |
2977 // state are deeply merged as base for persisted value. |
2889 initialState = Object(external_this_lodash_["merge"])({}, initialState, persistedState); |
2978 initialState = Object(external_lodash_["merge"])({}, initialState, persistedState); |
2890 } else { |
2979 } else { |
2891 // If there is a mismatch in object-likeness of default |
2980 // If there is a mismatch in object-likeness of default |
2892 // initial or persisted state, defer to persisted value. |
2981 // initial or persisted state, defer to persisted value. |
2893 initialState = persistedState; |
2982 initialState = persistedState; |
2894 } |
2983 } |
2895 |
2984 |
2896 options = persistence_objectSpread({}, options, { |
2985 options = { ...options, |
2897 initialState: initialState |
2986 initialState |
2898 }); |
2987 }; |
2899 } |
2988 } |
2900 |
2989 |
2901 var store = registry.registerStore(reducerKey, options); |
2990 const store = registry.registerStore(storeName, options); |
2902 store.subscribe(createPersistOnChange(store.getState, reducerKey, options.persist)); |
2991 store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); |
2903 return store; |
2992 return store; |
2904 } |
2993 } |
|
2994 |
2905 }; |
2995 }; |
2906 } |
2996 } |
2907 /** |
2997 /** |
2908 * Deprecated: Remove this function and the code in WordPress Core that calls |
2998 * Deprecated: Remove this function and the code in WordPress Core that calls |
2909 * it once WordPress 5.4 is released. |
2999 * it once WordPress 5.4 is released. |
2910 */ |
3000 */ |
2911 |
3001 |
2912 |
3002 |
2913 persistencePlugin.__unstableMigrate = function (pluginOptions) { |
3003 persistencePlugin.__unstableMigrate = pluginOptions => { |
2914 var persistence = createPersistenceInterface(pluginOptions); |
3004 var _state$coreEditor, _state$coreEditor$pre; |
2915 var state = persistence.get(); // Migrate 'insertUsage' from 'core/editor' to 'core/block-editor' |
3005 |
2916 |
3006 const persistence = createPersistenceInterface(pluginOptions); |
2917 var insertUsage = Object(external_this_lodash_["get"])(state, ['core/editor', 'preferences', 'insertUsage']); |
3007 const state = persistence.get(); // Migrate 'insertUsage' from 'core/editor' to 'core/block-editor' |
2918 |
3008 |
2919 if (insertUsage) { |
3009 const editorInsertUsage = (_state$coreEditor = state['core/editor']) === null || _state$coreEditor === void 0 ? void 0 : (_state$coreEditor$pre = _state$coreEditor.preferences) === null || _state$coreEditor$pre === void 0 ? void 0 : _state$coreEditor$pre.insertUsage; |
|
3010 |
|
3011 if (editorInsertUsage) { |
|
3012 var _state$coreBlockEdi, _state$coreBlockEdi$p; |
|
3013 |
|
3014 const blockEditorInsertUsage = (_state$coreBlockEdi = state['core/block-editor']) === null || _state$coreBlockEdi === void 0 ? void 0 : (_state$coreBlockEdi$p = _state$coreBlockEdi.preferences) === null || _state$coreBlockEdi$p === void 0 ? void 0 : _state$coreBlockEdi$p.insertUsage; |
2920 persistence.set('core/block-editor', { |
3015 persistence.set('core/block-editor', { |
2921 preferences: { |
3016 preferences: { |
2922 insertUsage: insertUsage |
3017 insertUsage: { ...editorInsertUsage, |
|
3018 ...blockEditorInsertUsage |
|
3019 } |
2923 } |
3020 } |
2924 }); |
3021 }); |
2925 } |
3022 } |
2926 |
3023 |
2927 var editPostState = state['core/edit-post']; // Default `fullscreenMode` to `false` if any persisted state had existed |
3024 let editPostState = state['core/edit-post']; // Default `fullscreenMode` to `false` if any persisted state had existed |
2928 // and the user hadn't made an explicit choice about fullscreen mode. This |
3025 // and the user hadn't made an explicit choice about fullscreen mode. This |
2929 // is needed since `fullscreenMode` previously did not have a default value |
3026 // is needed since `fullscreenMode` previously did not have a default value |
2930 // and was implicitly false by its absence. It is now `true` by default, but |
3027 // and was implicitly false by its absence. It is now `true` by default, but |
2931 // this change is not intended to affect upgrades from earlier versions. |
3028 // this change is not intended to affect upgrades from earlier versions. |
2932 |
3029 |
2933 var hadPersistedState = Object.keys(state).length > 0; |
3030 const hadPersistedState = Object.keys(state).length > 0; |
2934 var hadFullscreenModePreference = Object(external_this_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'fullscreenMode']); |
3031 const hadFullscreenModePreference = Object(external_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'fullscreenMode']); |
2935 |
3032 |
2936 if (hadPersistedState && !hadFullscreenModePreference) { |
3033 if (hadPersistedState && !hadFullscreenModePreference) { |
2937 editPostState = Object(external_this_lodash_["merge"])({}, editPostState, { |
3034 editPostState = Object(external_lodash_["merge"])({}, editPostState, { |
2938 preferences: { |
3035 preferences: { |
2939 features: { |
3036 features: { |
2940 fullscreenMode: false |
3037 fullscreenMode: false |
2941 } |
3038 } |
2942 } |
3039 } |
2943 }); |
3040 }); |
2944 } // Migrate 'areTipsEnabled' from 'core/nux' to 'showWelcomeGuide' in 'core/edit-post' |
3041 } // Migrate 'areTipsEnabled' from 'core/nux' to 'showWelcomeGuide' in 'core/edit-post' |
2945 |
3042 |
2946 |
3043 |
2947 var areTipsEnabled = Object(external_this_lodash_["get"])(state, ['core/nux', 'preferences', 'areTipsEnabled']); |
3044 const areTipsEnabled = Object(external_lodash_["get"])(state, ['core/nux', 'preferences', 'areTipsEnabled']); |
2948 var hasWelcomeGuide = Object(external_this_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'welcomeGuide']); |
3045 const hasWelcomeGuide = Object(external_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'welcomeGuide']); |
2949 |
3046 |
2950 if (areTipsEnabled !== undefined && !hasWelcomeGuide) { |
3047 if (areTipsEnabled !== undefined && !hasWelcomeGuide) { |
2951 editPostState = Object(external_this_lodash_["merge"])({}, editPostState, { |
3048 editPostState = Object(external_lodash_["merge"])({}, editPostState, { |
2952 preferences: { |
3049 preferences: { |
2953 features: { |
3050 features: { |
2954 welcomeGuide: areTipsEnabled |
3051 welcomeGuide: areTipsEnabled |
2955 } |
3052 } |
2956 } |
3053 } |
2967 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/index.js |
3064 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/index.js |
2968 |
3065 |
2969 |
3066 |
2970 |
3067 |
2971 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
3068 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
2972 var esm_extends = __webpack_require__(8); |
3069 var esm_extends = __webpack_require__("wx14"); |
2973 |
3070 |
2974 // EXTERNAL MODULE: external {"this":["wp","element"]} |
3071 // EXTERNAL MODULE: external ["wp","element"] |
2975 var external_this_wp_element_ = __webpack_require__(0); |
3072 var external_wp_element_ = __webpack_require__("GRId"); |
2976 |
3073 |
2977 // EXTERNAL MODULE: external {"this":["wp","compose"]} |
3074 // EXTERNAL MODULE: external ["wp","compose"] |
2978 var external_this_wp_compose_ = __webpack_require__(9); |
3075 var external_wp_compose_ = __webpack_require__("K9lf"); |
2979 |
3076 |
2980 // EXTERNAL MODULE: external {"this":"React"} |
3077 // EXTERNAL MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
2981 var external_this_React_ = __webpack_require__(13); |
3078 var use_memo_one_esm = __webpack_require__("mHlH"); |
2982 |
3079 |
2983 // CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
3080 // EXTERNAL MODULE: external ["wp","priorityQueue"] |
2984 |
3081 var external_wp_priorityQueue_ = __webpack_require__("XI5e"); |
2985 |
3082 |
2986 function areInputsEqual(newInputs, lastInputs) { |
3083 // EXTERNAL MODULE: external ["wp","isShallowEqual"] |
2987 if (newInputs.length !== lastInputs.length) { |
3084 var external_wp_isShallowEqual_ = __webpack_require__("rl8x"); |
2988 return false; |
3085 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
2989 } |
|
2990 |
|
2991 for (var i = 0; i < newInputs.length; i++) { |
|
2992 if (newInputs[i] !== lastInputs[i]) { |
|
2993 return false; |
|
2994 } |
|
2995 } |
|
2996 |
|
2997 return true; |
|
2998 } |
|
2999 |
|
3000 function useMemoOne(getResult, inputs) { |
|
3001 var initial = Object(external_this_React_["useState"])(function () { |
|
3002 return { |
|
3003 inputs: inputs, |
|
3004 result: getResult() |
|
3005 }; |
|
3006 })[0]; |
|
3007 var committed = Object(external_this_React_["useRef"])(initial); |
|
3008 var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
|
3009 var cache = isInputMatch ? committed.current : { |
|
3010 inputs: inputs, |
|
3011 result: getResult() |
|
3012 }; |
|
3013 Object(external_this_React_["useEffect"])(function () { |
|
3014 committed.current = cache; |
|
3015 }, [cache]); |
|
3016 return cache.result; |
|
3017 } |
|
3018 function useCallbackOne(callback, inputs) { |
|
3019 return useMemoOne(function () { |
|
3020 return callback; |
|
3021 }, inputs); |
|
3022 } |
|
3023 var useMemo = useMemoOne; |
|
3024 var useCallback = useCallbackOne; |
|
3025 |
|
3026 |
|
3027 |
|
3028 // EXTERNAL MODULE: external {"this":["wp","priorityQueue"]} |
|
3029 var external_this_wp_priorityQueue_ = __webpack_require__(150); |
|
3030 |
|
3031 // EXTERNAL MODULE: external {"this":["wp","isShallowEqual"]} |
|
3032 var external_this_wp_isShallowEqual_ = __webpack_require__(64); |
|
3033 var external_this_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_isShallowEqual_); |
|
3034 |
3086 |
3035 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js |
3087 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js |
3036 /** |
3088 /** |
3037 * WordPress dependencies |
3089 * WordPress dependencies |
3038 */ |
3090 */ |
3214 */ |
3268 */ |
3215 |
3269 |
3216 |
3270 |
3217 |
3271 |
3218 |
3272 |
|
3273 |
3219 /** |
3274 /** |
3220 * Internal dependencies |
3275 * Internal dependencies |
3221 */ |
3276 */ |
3222 |
3277 |
3223 |
3278 |
3224 |
3279 |
3225 /** |
3280 const renderQueue = Object(external_wp_priorityQueue_["createQueue"])(); |
3226 * Favor useLayoutEffect to ensure the store subscription callback always has |
3281 /** @typedef {import('./types').WPDataStore} WPDataStore */ |
3227 * the selector from the latest render. If a store update happens between render |
3282 |
3228 * and the effect, this could cause missed/stale updates or inconsistent state. |
|
3229 * |
|
3230 * Fallback to useEffect for server rendered components because currently React |
|
3231 * throws a warning when using useLayoutEffect in that environment. |
|
3232 */ |
|
3233 |
|
3234 var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_this_wp_element_["useLayoutEffect"] : external_this_wp_element_["useEffect"]; |
|
3235 var renderQueue = Object(external_this_wp_priorityQueue_["createQueue"])(); |
|
3236 /** |
3283 /** |
3237 * Custom react hook for retrieving props from registered selectors. |
3284 * Custom react hook for retrieving props from registered selectors. |
3238 * |
3285 * |
3239 * In general, this custom React hook follows the |
3286 * In general, this custom React hook follows the |
3240 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html). |
3287 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html). |
3241 * |
3288 * |
3242 * @param {Function} _mapSelect Function called on every state change. The |
3289 * @param {Function|WPDataStore|string} _mapSelect Function called on every state change. The |
3243 * returned value is exposed to the component |
3290 * returned value is exposed to the component |
3244 * implementing this hook. The function receives |
3291 * implementing this hook. The function receives |
3245 * the `registry.select` method on the first |
3292 * the `registry.select` method on the first |
3246 * argument and the `registry` on the second |
3293 * argument and the `registry` on the second |
3247 * argument. |
3294 * argument. |
3248 * @param {Array} deps If provided, this memoizes the mapSelect so the |
3295 * When a store key is passed, all selectors for |
3249 * same `mapSelect` is invoked on every state |
3296 * the store will be returned. This is only meant |
3250 * change unless the dependencies change. |
3297 * for usage of these selectors in event |
|
3298 * callbacks, not for data needed to create the |
|
3299 * element tree. |
|
3300 * @param {Array} deps If provided, this memoizes the mapSelect so the |
|
3301 * same `mapSelect` is invoked on every state |
|
3302 * change unless the dependencies change. |
3251 * |
3303 * |
3252 * @example |
3304 * @example |
3253 * ```js |
3305 * ```js |
3254 * const { useSelect } = wp.data; |
3306 * import { useSelect } from '@wordpress/data'; |
3255 * |
3307 * |
3256 * function HammerPriceDisplay( { currency } ) { |
3308 * function HammerPriceDisplay( { currency } ) { |
3257 * const price = useSelect( ( select ) => { |
3309 * const price = useSelect( ( select ) => { |
3258 * return select( 'my-shop' ).getPrice( 'hammer', currency ) |
3310 * return select( 'my-shop' ).getPrice( 'hammer', currency ) |
3259 * }, [ currency ] ); |
3311 * }, [ currency ] ); |
3272 * `mapSelect` callback on `useSelect`. If the currency prop changes then |
3324 * `mapSelect` callback on `useSelect`. If the currency prop changes then |
3273 * any price in the state for that currency is retrieved. If the currency prop |
3325 * any price in the state for that currency is retrieved. If the currency prop |
3274 * doesn't change and other props are passed in that do change, the price will |
3326 * doesn't change and other props are passed in that do change, the price will |
3275 * not change because the dependency is just the currency. |
3327 * not change because the dependency is just the currency. |
3276 * |
3328 * |
|
3329 * When data is only used in an event callback, the data should not be retrieved |
|
3330 * on render, so it may be useful to get the selectors function instead. |
|
3331 * |
|
3332 * **Don't use `useSelect` this way when calling the selectors in the render |
|
3333 * function because your component won't re-render on a data change.** |
|
3334 * |
|
3335 * ```js |
|
3336 * import { useSelect } from '@wordpress/data'; |
|
3337 * |
|
3338 * function Paste( { children } ) { |
|
3339 * const { getSettings } = useSelect( 'my-shop' ); |
|
3340 * function onPaste() { |
|
3341 * // Do something with the settings. |
|
3342 * const settings = getSettings(); |
|
3343 * } |
|
3344 * return <div onPaste={ onPaste }>{ children }</div>; |
|
3345 * } |
|
3346 * ``` |
|
3347 * |
3277 * @return {Function} A custom react hook. |
3348 * @return {Function} A custom react hook. |
3278 */ |
3349 */ |
3279 |
3350 |
3280 function useSelect(_mapSelect, deps) { |
3351 function useSelect(_mapSelect, deps) { |
3281 var mapSelect = Object(external_this_wp_element_["useCallback"])(_mapSelect, deps); |
3352 const isWithoutMapping = typeof _mapSelect !== 'function'; |
3282 var registry = useRegistry(); |
3353 |
3283 var isAsync = useAsyncMode(); // React can sometimes clear the `useMemo` cache. |
3354 if (isWithoutMapping) { |
|
3355 deps = []; |
|
3356 } |
|
3357 |
|
3358 const mapSelect = Object(external_wp_element_["useCallback"])(_mapSelect, deps); |
|
3359 const registry = useRegistry(); |
|
3360 const isAsync = useAsyncMode(); // React can sometimes clear the `useMemo` cache. |
3284 // We use the cache-stable `useMemoOne` to avoid |
3361 // We use the cache-stable `useMemoOne` to avoid |
3285 // losing queues. |
3362 // losing queues. |
3286 |
3363 |
3287 var queueContext = useMemoOne(function () { |
3364 const queueContext = Object(use_memo_one_esm["a" /* useMemoOne */])(() => ({ |
3288 return { |
3365 queue: true |
3289 queue: true |
3366 }), [registry]); |
3290 }; |
3367 const [, forceRender] = Object(external_wp_element_["useReducer"])(s => s + 1, 0); |
3291 }, [registry]); |
3368 const latestMapSelect = Object(external_wp_element_["useRef"])(); |
3292 |
3369 const latestIsAsync = Object(external_wp_element_["useRef"])(isAsync); |
3293 var _useReducer = Object(external_this_wp_element_["useReducer"])(function (s) { |
3370 const latestMapOutput = Object(external_wp_element_["useRef"])(); |
3294 return s + 1; |
3371 const latestMapOutputError = Object(external_wp_element_["useRef"])(); |
3295 }, 0), |
3372 const isMountedAndNotUnsubscribing = Object(external_wp_element_["useRef"])(); // Keep track of the stores being selected in the mapSelect function, |
3296 _useReducer2 = Object(slicedToArray["a" /* default */])(_useReducer, 2), |
3373 // and only subscribe to those stores later. |
3297 forceRender = _useReducer2[1]; |
3374 |
3298 |
3375 const listeningStores = Object(external_wp_element_["useRef"])([]); |
3299 var latestMapSelect = Object(external_this_wp_element_["useRef"])(); |
3376 const trapSelect = Object(external_wp_element_["useCallback"])(callback => registry.__experimentalMarkListeningStores(callback, listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array. |
3300 var latestIsAsync = Object(external_this_wp_element_["useRef"])(isAsync); |
3377 // It's different than just using `mapSelect` since deps could be undefined, |
3301 var latestMapOutput = Object(external_this_wp_element_["useRef"])(); |
3378 // in that case, we would still want to memoize it. |
3302 var latestMapOutputError = Object(external_this_wp_element_["useRef"])(); |
3379 |
3303 var isMountedAndNotUnsubscribing = Object(external_this_wp_element_["useRef"])(); |
3380 const depsChangedFlag = Object(external_wp_element_["useMemo"])(() => ({}), deps || []); |
3304 var mapOutput; |
3381 let mapOutput; |
3305 |
3382 |
3306 try { |
3383 if (!isWithoutMapping) { |
3307 if (latestMapSelect.current !== mapSelect || latestMapOutputError.current) { |
3384 try { |
3308 mapOutput = mapSelect(registry.select, registry); |
3385 if (latestMapSelect.current !== mapSelect || latestMapOutputError.current) { |
3309 } else { |
3386 mapOutput = trapSelect(() => mapSelect(registry.select, registry)); |
|
3387 } else { |
|
3388 mapOutput = latestMapOutput.current; |
|
3389 } |
|
3390 } catch (error) { |
|
3391 let errorMessage = `An error occurred while running 'mapSelect': ${error.message}`; |
|
3392 |
|
3393 if (latestMapOutputError.current) { |
|
3394 errorMessage += `\nThe error may be correlated with this previous error:\n`; |
|
3395 errorMessage += `${latestMapOutputError.current.stack}\n\n`; |
|
3396 errorMessage += 'Original stack trace:'; |
|
3397 } // eslint-disable-next-line no-console |
|
3398 |
|
3399 |
|
3400 console.error(errorMessage); |
3310 mapOutput = latestMapOutput.current; |
3401 mapOutput = latestMapOutput.current; |
3311 } |
3402 } |
3312 } catch (error) { |
3403 } |
3313 var errorMessage = "An error occurred while running 'mapSelect': ".concat(error.message); |
3404 |
3314 |
3405 Object(external_wp_compose_["useIsomorphicLayoutEffect"])(() => { |
3315 if (latestMapOutputError.current) { |
3406 if (isWithoutMapping) { |
3316 errorMessage += "\nThe error may be correlated with this previous error:\n"; |
3407 return; |
3317 errorMessage += "".concat(latestMapOutputError.current.stack, "\n\n"); |
3408 } |
3318 errorMessage += 'Original stack trace:'; |
3409 |
3319 throw new Error(errorMessage); |
|
3320 } else { |
|
3321 // eslint-disable-next-line no-console |
|
3322 console.error(errorMessage); |
|
3323 } |
|
3324 } |
|
3325 |
|
3326 useIsomorphicLayoutEffect(function () { |
|
3327 latestMapSelect.current = mapSelect; |
3410 latestMapSelect.current = mapSelect; |
3328 latestMapOutput.current = mapOutput; |
3411 latestMapOutput.current = mapOutput; |
3329 latestMapOutputError.current = undefined; |
3412 latestMapOutputError.current = undefined; |
3330 isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates |
3413 isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates |
3331 // to avoid using stale values in the flushed |
3414 // to avoid using stale values in the flushed |
3644 * @param {WPComponent} OriginalComponent Original component. |
3706 * @param {WPComponent} OriginalComponent Original component. |
3645 * |
3707 * |
3646 * @return {WPComponent} Enhanced component. |
3708 * @return {WPComponent} Enhanced component. |
3647 */ |
3709 */ |
3648 |
3710 |
3649 var withRegistry = Object(external_this_wp_compose_["createHigherOrderComponent"])(function (OriginalComponent) { |
3711 const withRegistry = Object(external_wp_compose_["createHigherOrderComponent"])(OriginalComponent => props => Object(external_wp_element_["createElement"])(RegistryConsumer, null, registry => Object(external_wp_element_["createElement"])(OriginalComponent, Object(esm_extends["a" /* default */])({}, props, { |
3650 return function (props) { |
3712 registry: registry |
3651 return Object(external_this_wp_element_["createElement"])(RegistryConsumer, null, function (registry) { |
3713 }))), 'withRegistry'); |
3652 return Object(external_this_wp_element_["createElement"])(OriginalComponent, Object(esm_extends["a" /* default */])({}, props, { |
|
3653 registry: registry |
|
3654 })); |
|
3655 }); |
|
3656 }; |
|
3657 }, 'withRegistry'); |
|
3658 /* harmony default export */ var with_registry = (withRegistry); |
3714 /* harmony default export */ var with_registry = (withRegistry); |
3659 |
3715 |
3660 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js |
3716 // CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js |
3661 /** |
3717 /** |
3662 * Internal dependencies |
3718 * Internal dependencies |
3663 */ |
3719 */ |
|
3720 |
|
3721 /** @typedef {import('./types').WPDataStore} WPDataStore */ |
3664 |
3722 |
3665 /** |
3723 /** |
3666 * A custom react hook returning the current registry dispatch actions creators. |
3724 * A custom react hook returning the current registry dispatch actions creators. |
3667 * |
3725 * |
3668 * Note: The component using this hook must be within the context of a |
3726 * Note: The component using this hook must be within the context of a |
3669 * RegistryProvider. |
3727 * RegistryProvider. |
3670 * |
3728 * |
3671 * @param {string} [storeName] Optionally provide the name of the store from |
3729 * @param {string|WPDataStore} [storeNameOrDefinition] Optionally provide the name of the |
3672 * which to retrieve action creators. If not |
3730 * store or its definition from which to |
3673 * provided, the registry.dispatch function is |
3731 * retrieve action creators. If not |
3674 * returned instead. |
3732 * provided, the registry.dispatch |
|
3733 * function is returned instead. |
3675 * |
3734 * |
3676 * @example |
3735 * @example |
3677 * This illustrates a pattern where you may need to retrieve dynamic data from |
3736 * This illustrates a pattern where you may need to retrieve dynamic data from |
3678 * the server via the `useSelect` hook to use in combination with the dispatch |
3737 * the server via the `useSelect` hook to use in combination with the dispatch |
3679 * action. |
3738 * action. |
3680 * |
3739 * |
3681 * ```jsx |
3740 * ```jsx |
3682 * const { useDispatch, useSelect } = wp.data; |
3741 * import { useDispatch, useSelect } from '@wordpress/data'; |
3683 * const { useCallback } = wp.element; |
3742 * import { useCallback } from '@wordpress/element'; |
3684 * |
3743 * |
3685 * function Button( { onClick, children } ) { |
3744 * function Button( { onClick, children } ) { |
3686 * return <button type="button" onClick={ onClick }>{ children }</button> |
3745 * return <button type="button" onClick={ onClick }>{ children }</button> |
3687 * } |
3746 * } |
3688 * |
3747 * |
3819 * return action.type === 'START_SALE' ? |
3831 * return action.type === 'START_SALE' ? |
3820 * action.discountPercent : |
3832 * action.discountPercent : |
3821 * state; |
3833 * state; |
3822 * }; |
3834 * }; |
3823 * |
3835 * |
3824 * registerStore( 'my-shop', { |
3836 * const store = createReduxStore( 'my-shop', { |
3825 * reducer: combineReducers( { |
3837 * reducer: combineReducers( { |
3826 * prices, |
3838 * prices, |
3827 * discountPercent, |
3839 * discountPercent, |
3828 * } ), |
3840 * } ), |
3829 * } ); |
3841 * } ); |
|
3842 * register( store ); |
3830 * ``` |
3843 * ``` |
3831 * |
3844 * |
3832 * @return {Function} A reducer that invokes every reducer inside the reducers |
3845 * @return {Function} A reducer that invokes every reducer inside the reducers |
3833 * object, and constructs a state object with the same shape. |
3846 * object, and constructs a state object with the same shape. |
3834 */ |
3847 */ |
3835 |
3848 |
3836 |
3849 |
3837 /** |
3850 /** |
3838 * Given the name of a registered store, returns an object of the store's selectors. |
3851 * Given the name or definition of a registered store, returns an object of the store's selectors. |
3839 * The selector functions are been pre-bound to pass the current state automatically. |
3852 * The selector functions are been pre-bound to pass the current state automatically. |
3840 * As a consumer, you need only pass arguments of the selector, if applicable. |
3853 * As a consumer, you need only pass arguments of the selector, if applicable. |
3841 * |
3854 * |
3842 * @param {string} name Store name. |
3855 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
|
3856 * or the store definition. |
3843 * |
3857 * |
3844 * @example |
3858 * @example |
3845 * ```js |
3859 * ```js |
3846 * const { select } = wp.data; |
3860 * import { select } from '@wordpress/data'; |
3847 * |
3861 * |
3848 * select( 'my-shop' ).getPrice( 'hammer' ); |
3862 * select( 'my-shop' ).getPrice( 'hammer' ); |
3849 * ``` |
3863 * ``` |
3850 * |
3864 * |
3851 * @return {Object} Object containing the store's selectors. |
3865 * @return {Object} Object containing the store's selectors. |
3852 */ |
3866 */ |
3853 |
3867 |
3854 var build_module_select = default_registry.select; |
3868 const build_module_select = default_registry.select; |
3855 /** |
3869 /** |
3856 * Given the name of a registered store, returns an object containing the store's |
3870 * Given the name of a registered store, returns an object containing the store's |
3857 * selectors pre-bound to state so that you only need to supply additional arguments, |
3871 * selectors pre-bound to state so that you only need to supply additional arguments, |
3858 * and modified so that they return promises that resolve to their eventual values, |
3872 * and modified so that they return promises that resolve to their eventual values, |
3859 * after any resolvers have ran. |
3873 * after any resolvers have ran. |
3860 * |
3874 * |
3861 * @param {string} name Store name. |
3875 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
|
3876 * or the store definition. |
3862 * |
3877 * |
3863 * @example |
3878 * @example |
3864 * ```js |
3879 * ```js |
3865 * const { __experimentalResolveSelect } = wp.data; |
3880 * import { resolveSelect } from '@wordpress/data'; |
3866 * |
3881 * |
3867 * __experimentalResolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log) |
3882 * resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log) |
3868 * ``` |
3883 * ``` |
3869 * |
3884 * |
3870 * @return {Object} Object containing the store's promise-wrapped selectors. |
3885 * @return {Object} Object containing the store's promise-wrapped selectors. |
3871 */ |
3886 */ |
3872 |
3887 |
3873 var build_module_experimentalResolveSelect = default_registry.__experimentalResolveSelect; |
3888 const build_module_resolveSelect = default_registry.resolveSelect; |
3874 /** |
3889 /** |
3875 * Given the name of a registered store, returns an object of the store's action creators. |
3890 * Given the name of a registered store, returns an object of the store's action creators. |
3876 * Calling an action creator will cause it to be dispatched, updating the state value accordingly. |
3891 * Calling an action creator will cause it to be dispatched, updating the state value accordingly. |
3877 * |
3892 * |
3878 * Note: Action creators returned by the dispatch will return a promise when |
3893 * Note: Action creators returned by the dispatch will return a promise when |
3879 * they are called. |
3894 * they are called. |
3880 * |
3895 * |
3881 * @param {string} name Store name. |
3896 * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
|
3897 * or the store definition. |
3882 * |
3898 * |
3883 * @example |
3899 * @example |
3884 * ```js |
3900 * ```js |
3885 * const { dispatch } = wp.data; |
3901 * import { dispatch } from '@wordpress/data'; |
3886 * |
3902 * |
3887 * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); |
3903 * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); |
3888 * ``` |
3904 * ``` |
3889 * @return {Object} Object containing the action creators. |
3905 * @return {Object} Object containing the action creators. |
3890 */ |
3906 */ |
3891 |
3907 |
3892 var build_module_dispatch = default_registry.dispatch; |
3908 const build_module_dispatch = default_registry.dispatch; |
3893 /** |
3909 /** |
3894 * Given a listener function, the function will be called any time the state value |
3910 * Given a listener function, the function will be called any time the state value |
3895 * of one of the registered stores has changed. This function returns a `unsubscribe` |
3911 * of one of the registered stores has changed. This function returns a `unsubscribe` |
3896 * function used to stop the subscription. |
3912 * function used to stop the subscription. |
3897 * |
3913 * |
3898 * @param {Function} listener Callback function. |
3914 * @param {Function} listener Callback function. |
3899 * |
3915 * |
3900 * @example |
3916 * @example |
3901 * ```js |
3917 * ```js |
3902 * const { subscribe } = wp.data; |
3918 * import { subscribe } from '@wordpress/data'; |
3903 * |
3919 * |
3904 * const unsubscribe = subscribe( () => { |
3920 * const unsubscribe = subscribe( () => { |
3905 * // You could use this opportunity to test whether the derived result of a |
3921 * // You could use this opportunity to test whether the derived result of a |
3906 * // selector has subsequently changed as the result of a state update. |
3922 * // selector has subsequently changed as the result of a state update. |
3907 * } ); |
3923 * } ); |
3909 * // Later, if necessary... |
3925 * // Later, if necessary... |
3910 * unsubscribe(); |
3926 * unsubscribe(); |
3911 * ``` |
3927 * ``` |
3912 */ |
3928 */ |
3913 |
3929 |
3914 var build_module_subscribe = default_registry.subscribe; |
3930 const build_module_subscribe = default_registry.subscribe; |
3915 /** |
3931 /** |
3916 * Registers a generic store. |
3932 * Registers a generic store. |
|
3933 * |
|
3934 * @deprecated Use `register` instead. |
3917 * |
3935 * |
3918 * @param {string} key Store registry key. |
3936 * @param {string} key Store registry key. |
3919 * @param {Object} config Configuration (getSelectors, getActions, subscribe). |
3937 * @param {Object} config Configuration (getSelectors, getActions, subscribe). |
3920 */ |
3938 */ |
3921 |
3939 |
3922 var build_module_registerGenericStore = default_registry.registerGenericStore; |
3940 const build_module_registerGenericStore = default_registry.registerGenericStore; |
3923 /** |
3941 /** |
3924 * Registers a standard `@wordpress/data` store. |
3942 * Registers a standard `@wordpress/data` store. |
3925 * |
3943 * |
3926 * @param {string} reducerKey Reducer key. |
3944 * @deprecated Use `register` instead. |
3927 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
3945 * |
|
3946 * @param {string} storeName Unique namespace identifier for the store. |
|
3947 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
3928 * |
3948 * |
3929 * @return {Object} Registered store object. |
3949 * @return {Object} Registered store object. |
3930 */ |
3950 */ |
3931 |
3951 |
3932 var build_module_registerStore = default_registry.registerStore; |
3952 const registerStore = default_registry.registerStore; |
3933 /** |
3953 /** |
3934 * Extends a registry to inherit functionality provided by a given plugin. A |
3954 * Extends a registry to inherit functionality provided by a given plugin. A |
3935 * plugin is an object with properties aligning to that of a registry, merged |
3955 * plugin is an object with properties aligning to that of a registry, merged |
3936 * to extend the default registry behavior. |
3956 * to extend the default registry behavior. |
3937 * |
3957 * |
3938 * @param {Object} plugin Plugin object. |
3958 * @param {Object} plugin Plugin object. |
3939 */ |
3959 */ |
3940 |
3960 |
3941 var build_module_use = default_registry.use; |
3961 const build_module_use = default_registry.use; |
|
3962 /** |
|
3963 * Registers a standard `@wordpress/data` store definition. |
|
3964 * |
|
3965 * @example |
|
3966 * ```js |
|
3967 * import { createReduxStore, register } from '@wordpress/data'; |
|
3968 * |
|
3969 * const store = createReduxStore( 'demo', { |
|
3970 * reducer: ( state = 'OK' ) => state, |
|
3971 * selectors: { |
|
3972 * getValue: ( state ) => state, |
|
3973 * }, |
|
3974 * } ); |
|
3975 * register( store ); |
|
3976 * ``` |
|
3977 * |
|
3978 * @param {WPDataStore} store Store definition. |
|
3979 */ |
|
3980 |
|
3981 const build_module_register = default_registry.register; |
3942 |
3982 |
3943 |
3983 |
3944 /***/ }), |
3984 /***/ }), |
3945 |
3985 |
3946 /***/ 5: |
3986 /***/ "rl8x": |
3947 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
3987 /***/ (function(module, exports) { |
3948 |
3988 |
3949 "use strict"; |
3989 (function() { module.exports = window["wp"]["isShallowEqual"]; }()); |
3950 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; }); |
|
3951 function _defineProperty(obj, key, value) { |
|
3952 if (key in obj) { |
|
3953 Object.defineProperty(obj, key, { |
|
3954 value: value, |
|
3955 enumerable: true, |
|
3956 configurable: true, |
|
3957 writable: true |
|
3958 }); |
|
3959 } else { |
|
3960 obj[key] = value; |
|
3961 } |
|
3962 |
|
3963 return obj; |
|
3964 } |
|
3965 |
3990 |
3966 /***/ }), |
3991 /***/ }), |
3967 |
3992 |
3968 /***/ 50: |
3993 /***/ "wx14": |
3969 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
3970 |
|
3971 "use strict"; |
|
3972 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; }); |
|
3973 function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { |
|
3974 try { |
|
3975 var info = gen[key](arg); |
|
3976 var value = info.value; |
|
3977 } catch (error) { |
|
3978 reject(error); |
|
3979 return; |
|
3980 } |
|
3981 |
|
3982 if (info.done) { |
|
3983 resolve(value); |
|
3984 } else { |
|
3985 Promise.resolve(value).then(_next, _throw); |
|
3986 } |
|
3987 } |
|
3988 |
|
3989 function _asyncToGenerator(fn) { |
|
3990 return function () { |
|
3991 var self = this, |
|
3992 args = arguments; |
|
3993 return new Promise(function (resolve, reject) { |
|
3994 var gen = fn.apply(self, args); |
|
3995 |
|
3996 function _next(value) { |
|
3997 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); |
|
3998 } |
|
3999 |
|
4000 function _throw(err) { |
|
4001 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); |
|
4002 } |
|
4003 |
|
4004 _next(undefined); |
|
4005 }); |
|
4006 }; |
|
4007 } |
|
4008 |
|
4009 /***/ }), |
|
4010 |
|
4011 /***/ 60: |
|
4012 /***/ (function(module, exports, __webpack_require__) { |
|
4013 |
|
4014 /** |
|
4015 * Memize options object. |
|
4016 * |
|
4017 * @typedef MemizeOptions |
|
4018 * |
|
4019 * @property {number} [maxSize] Maximum size of the cache. |
|
4020 */ |
|
4021 |
|
4022 /** |
|
4023 * Internal cache entry. |
|
4024 * |
|
4025 * @typedef MemizeCacheNode |
|
4026 * |
|
4027 * @property {?MemizeCacheNode|undefined} [prev] Previous node. |
|
4028 * @property {?MemizeCacheNode|undefined} [next] Next node. |
|
4029 * @property {Array<*>} args Function arguments for cache |
|
4030 * entry. |
|
4031 * @property {*} val Function result. |
|
4032 */ |
|
4033 |
|
4034 /** |
|
4035 * Properties of the enhanced function for controlling cache. |
|
4036 * |
|
4037 * @typedef MemizeMemoizedFunction |
|
4038 * |
|
4039 * @property {()=>void} clear Clear the cache. |
|
4040 */ |
|
4041 |
|
4042 /** |
|
4043 * Accepts a function to be memoized, and returns a new memoized function, with |
|
4044 * optional options. |
|
4045 * |
|
4046 * @template {Function} F |
|
4047 * |
|
4048 * @param {F} fn Function to memoize. |
|
4049 * @param {MemizeOptions} [options] Options object. |
|
4050 * |
|
4051 * @return {F & MemizeMemoizedFunction} Memoized function. |
|
4052 */ |
|
4053 function memize( fn, options ) { |
|
4054 var size = 0; |
|
4055 |
|
4056 /** @type {?MemizeCacheNode|undefined} */ |
|
4057 var head; |
|
4058 |
|
4059 /** @type {?MemizeCacheNode|undefined} */ |
|
4060 var tail; |
|
4061 |
|
4062 options = options || {}; |
|
4063 |
|
4064 function memoized( /* ...args */ ) { |
|
4065 var node = head, |
|
4066 len = arguments.length, |
|
4067 args, i; |
|
4068 |
|
4069 searchCache: while ( node ) { |
|
4070 // Perform a shallow equality test to confirm that whether the node |
|
4071 // under test is a candidate for the arguments passed. Two arrays |
|
4072 // are shallowly equal if their length matches and each entry is |
|
4073 // strictly equal between the two sets. Avoid abstracting to a |
|
4074 // function which could incur an arguments leaking deoptimization. |
|
4075 |
|
4076 // Check whether node arguments match arguments length |
|
4077 if ( node.args.length !== arguments.length ) { |
|
4078 node = node.next; |
|
4079 continue; |
|
4080 } |
|
4081 |
|
4082 // Check whether node arguments match arguments values |
|
4083 for ( i = 0; i < len; i++ ) { |
|
4084 if ( node.args[ i ] !== arguments[ i ] ) { |
|
4085 node = node.next; |
|
4086 continue searchCache; |
|
4087 } |
|
4088 } |
|
4089 |
|
4090 // At this point we can assume we've found a match |
|
4091 |
|
4092 // Surface matched node to head if not already |
|
4093 if ( node !== head ) { |
|
4094 // As tail, shift to previous. Must only shift if not also |
|
4095 // head, since if both head and tail, there is no previous. |
|
4096 if ( node === tail ) { |
|
4097 tail = node.prev; |
|
4098 } |
|
4099 |
|
4100 // Adjust siblings to point to each other. If node was tail, |
|
4101 // this also handles new tail's empty `next` assignment. |
|
4102 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next; |
|
4103 if ( node.next ) { |
|
4104 node.next.prev = node.prev; |
|
4105 } |
|
4106 |
|
4107 node.next = head; |
|
4108 node.prev = null; |
|
4109 /** @type {MemizeCacheNode} */ ( head ).prev = node; |
|
4110 head = node; |
|
4111 } |
|
4112 |
|
4113 // Return immediately |
|
4114 return node.val; |
|
4115 } |
|
4116 |
|
4117 // No cached value found. Continue to insertion phase: |
|
4118 |
|
4119 // Create a copy of arguments (avoid leaking deoptimization) |
|
4120 args = new Array( len ); |
|
4121 for ( i = 0; i < len; i++ ) { |
|
4122 args[ i ] = arguments[ i ]; |
|
4123 } |
|
4124 |
|
4125 node = { |
|
4126 args: args, |
|
4127 |
|
4128 // Generate the result from original function |
|
4129 val: fn.apply( null, args ), |
|
4130 }; |
|
4131 |
|
4132 // Don't need to check whether node is already head, since it would |
|
4133 // have been returned above already if it was |
|
4134 |
|
4135 // Shift existing head down list |
|
4136 if ( head ) { |
|
4137 head.prev = node; |
|
4138 node.next = head; |
|
4139 } else { |
|
4140 // If no head, follows that there's no tail (at initial or reset) |
|
4141 tail = node; |
|
4142 } |
|
4143 |
|
4144 // Trim tail if we're reached max size and are pending cache insertion |
|
4145 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) { |
|
4146 tail = /** @type {MemizeCacheNode} */ ( tail ).prev; |
|
4147 /** @type {MemizeCacheNode} */ ( tail ).next = null; |
|
4148 } else { |
|
4149 size++; |
|
4150 } |
|
4151 |
|
4152 head = node; |
|
4153 |
|
4154 return node.val; |
|
4155 } |
|
4156 |
|
4157 memoized.clear = function() { |
|
4158 head = null; |
|
4159 tail = null; |
|
4160 size = 0; |
|
4161 }; |
|
4162 |
|
4163 if ( false ) {} |
|
4164 |
|
4165 // Ignore reason: There's not a clear solution to create an intersection of |
|
4166 // the function with additional properties, where the goal is to retain the |
|
4167 // function signature of the incoming argument and add control properties |
|
4168 // on the return value. |
|
4169 |
|
4170 // @ts-ignore |
|
4171 return memoized; |
|
4172 } |
|
4173 |
|
4174 module.exports = memize; |
|
4175 |
|
4176 |
|
4177 /***/ }), |
|
4178 |
|
4179 /***/ 64: |
|
4180 /***/ (function(module, exports) { |
|
4181 |
|
4182 (function() { module.exports = this["wp"]["isShallowEqual"]; }()); |
|
4183 |
|
4184 /***/ }), |
|
4185 |
|
4186 /***/ 8: |
|
4187 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
3994 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
4188 |
3995 |
4189 "use strict"; |
3996 "use strict"; |
4190 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _extends; }); |
3997 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _extends; }); |
4191 function _extends() { |
3998 function _extends() { |