@wordpress/data 6.12.0 → 6.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +39 -27
  3. package/build/components/async-mode-provider/context.js +2 -1
  4. package/build/components/async-mode-provider/context.js.map +1 -1
  5. package/build/components/use-dispatch/use-dispatch.js +3 -2
  6. package/build/components/use-dispatch/use-dispatch.js.map +1 -1
  7. package/build/components/use-select/index.js +5 -2
  8. package/build/components/use-select/index.js.map +1 -1
  9. package/build/components/with-dispatch/index.js +5 -3
  10. package/build/components/with-dispatch/index.js.map +1 -1
  11. package/build/components/with-select/index.js +2 -1
  12. package/build/components/with-select/index.js.map +1 -1
  13. package/build/controls.js +8 -9
  14. package/build/controls.js.map +1 -1
  15. package/build/factory.js +5 -2
  16. package/build/factory.js.map +1 -1
  17. package/build/index.js +26 -20
  18. package/build/index.js.map +1 -1
  19. package/build/plugins/persistence/index.js +3 -1
  20. package/build/plugins/persistence/index.js.map +1 -1
  21. package/build/registry.js +21 -16
  22. package/build/registry.js.map +1 -1
  23. package/build-module/components/async-mode-provider/context.js +2 -1
  24. package/build-module/components/async-mode-provider/context.js.map +1 -1
  25. package/build-module/components/use-dispatch/use-dispatch.js +3 -2
  26. package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
  27. package/build-module/components/use-select/index.js +6 -3
  28. package/build-module/components/use-select/index.js.map +1 -1
  29. package/build-module/components/with-dispatch/index.js +5 -3
  30. package/build-module/components/with-dispatch/index.js.map +1 -1
  31. package/build-module/components/with-select/index.js +2 -1
  32. package/build-module/components/with-select/index.js.map +1 -1
  33. package/build-module/controls.js +5 -5
  34. package/build-module/controls.js.map +1 -1
  35. package/build-module/factory.js +5 -2
  36. package/build-module/factory.js.map +1 -1
  37. package/build-module/index.js +26 -20
  38. package/build-module/index.js.map +1 -1
  39. package/build-module/plugins/persistence/index.js +2 -1
  40. package/build-module/plugins/persistence/index.js.map +1 -1
  41. package/build-module/registry.js +17 -12
  42. package/build-module/registry.js.map +1 -1
  43. package/build-types/components/async-mode-provider/context.d.ts +5 -0
  44. package/build-types/components/async-mode-provider/context.d.ts.map +1 -0
  45. package/build-types/components/async-mode-provider/index.d.ts +3 -0
  46. package/build-types/components/async-mode-provider/index.d.ts.map +1 -0
  47. package/build-types/components/async-mode-provider/use-async-mode.d.ts +2 -0
  48. package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -0
  49. package/build-types/components/registry-provider/context.d.ts +36 -0
  50. package/build-types/components/registry-provider/context.d.ts.map +1 -0
  51. package/build-types/components/registry-provider/index.d.ts +3 -0
  52. package/build-types/components/registry-provider/index.d.ts.map +1 -0
  53. package/build-types/components/registry-provider/use-registry.d.ts +41 -0
  54. package/build-types/components/registry-provider/use-registry.d.ts.map +1 -0
  55. package/build-types/components/use-dispatch/index.d.ts +3 -0
  56. package/build-types/components/use-dispatch/index.d.ts.map +1 -0
  57. package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +17 -0
  58. package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -0
  59. package/build-types/components/use-dispatch/use-dispatch.d.ts +50 -0
  60. package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -0
  61. package/build-types/components/use-select/index.d.ts +99 -0
  62. package/build-types/components/use-select/index.d.ts.map +1 -0
  63. package/build-types/components/with-dispatch/index.d.ts +84 -0
  64. package/build-types/components/with-dispatch/index.d.ts.map +1 -0
  65. package/build-types/components/with-registry/index.d.ts +11 -0
  66. package/build-types/components/with-registry/index.d.ts.map +1 -0
  67. package/build-types/components/with-select/index.d.ts +43 -0
  68. package/build-types/components/with-select/index.d.ts.map +1 -0
  69. package/build-types/controls.d.ts +83 -0
  70. package/build-types/controls.d.ts.map +1 -0
  71. package/build-types/default-registry.d.ts +3 -0
  72. package/build-types/default-registry.d.ts.map +1 -0
  73. package/build-types/factory.d.ts +63 -0
  74. package/build-types/factory.d.ts.map +1 -0
  75. package/build-types/index.d.ts +156 -0
  76. package/build-types/index.d.ts.map +1 -0
  77. package/build-types/plugins/index.d.ts +2 -0
  78. package/build-types/plugins/index.d.ts.map +1 -0
  79. package/build-types/plugins/persistence/index.d.ts +41 -0
  80. package/build-types/plugins/persistence/index.d.ts.map +1 -0
  81. package/build-types/plugins/persistence/storage/default.d.ts +3 -0
  82. package/build-types/plugins/persistence/storage/default.d.ts.map +1 -0
  83. package/build-types/plugins/persistence/storage/object.d.ts +10 -0
  84. package/build-types/plugins/persistence/storage/object.d.ts.map +1 -0
  85. package/build-types/redux-store/index.d.ts +29 -0
  86. package/build-types/redux-store/index.d.ts.map +1 -0
  87. package/build-types/redux-store/thunk-middleware.d.ts +2 -0
  88. package/build-types/redux-store/thunk-middleware.d.ts.map +1 -0
  89. package/build-types/registry.d.ts +56 -0
  90. package/build-types/registry.d.ts.map +1 -0
  91. package/build-types/resolvers-cache-middleware.d.ts +15 -0
  92. package/build-types/resolvers-cache-middleware.d.ts.map +1 -0
  93. package/build-types/store/index.d.ts +23 -0
  94. package/build-types/store/index.d.ts.map +1 -0
  95. package/package.json +9 -8
  96. package/src/components/async-mode-provider/context.js +2 -1
  97. package/src/components/use-dispatch/use-dispatch.js +3 -2
  98. package/src/components/use-select/index.js +13 -3
  99. package/src/components/with-dispatch/index.js +5 -3
  100. package/src/components/with-select/index.js +2 -1
  101. package/src/controls.js +4 -5
  102. package/src/factory.js +5 -2
  103. package/src/index.js +26 -20
  104. package/src/plugins/persistence/index.js +2 -1
  105. package/src/registry.js +17 -12
  106. package/tsconfig.json +4 -2
  107. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.15.0 (2022-08-10)
6
+
7
+ ## 6.14.0 (2022-07-27)
8
+
9
+ ## 6.13.0 (2022-07-13)
10
+
11
+ ### Enhancements
12
+
13
+ - Use `useDebugValue` in `useSelect` to better display data in React DevTools ([#42225](https://github.com/WordPress/gutenberg/pull/42225)).
14
+
5
15
  ## 6.12.0 (2022-06-29)
6
16
 
7
17
  ## 6.11.0 (2022-06-15)
package/README.md CHANGED
@@ -278,10 +278,11 @@ _Usage_
278
278
 
279
279
  ```js
280
280
  import { useSelect, AsyncModeProvider } from '@wordpress/data';
281
+ import { store as blockEditorStore } from '@wordpress/block-editor';
281
282
 
282
283
  function BlockCount() {
283
284
  const count = useSelect( ( select ) => {
284
- return select( 'core/block-editor' ).getBlockCount();
285
+ return select( blockEditorStore ).getBlockCount();
285
286
  }, [] );
286
287
 
287
288
  return count;
@@ -446,15 +447,18 @@ that supports also selecting from other registered stores.
446
447
  _Usage_
447
448
 
448
449
  ```js
450
+ import { store as coreStore } from '@wordpress/core-data';
451
+ import { store as editorStore } from '@wordpress/editor';
452
+
449
453
  const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
450
- return select( 'core/editor' ).getCurrentPostId();
454
+ return select( editorStore ).getCurrentPostId();
451
455
  } );
452
456
 
453
457
  const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
454
458
  // calling another registry selector just like any other function
455
459
  const postType = getCurrentPostType( state );
456
460
  const postId = getCurrentPostId( state );
457
- return select( 'core' ).getEntityRecordEdits(
461
+ return select( coreStore ).getEntityRecordEdits(
458
462
  'postType',
459
463
  postType,
460
464
  postId
@@ -477,7 +481,7 @@ _Returns_
477
481
 
478
482
  ### dispatch
479
483
 
480
- Given the name of a registered store, returns an object of the store's action creators.
484
+ Given a store descriptor, returns an object of the store's action creators.
481
485
  Calling an action creator will cause it to be dispatched, updating the state value accordingly.
482
486
 
483
487
  Note: Action creators returned by the dispatch will return a promise when
@@ -487,13 +491,14 @@ _Usage_
487
491
 
488
492
  ```js
489
493
  import { dispatch } from '@wordpress/data';
494
+ import { store as myCustomStore } from 'my-custom-store';
490
495
 
491
- dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
496
+ dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
492
497
  ```
493
498
 
494
499
  _Parameters_
495
500
 
496
- - _storeNameOrDescriptor_ `string|StoreDescriptor`: Unique namespace identifier for the store or the store descriptor.
501
+ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
497
502
 
498
503
  _Returns_
499
504
 
@@ -602,22 +607,22 @@ example.
602
607
 
603
608
  ### resolveSelect
604
609
 
605
- Given the name of a registered store, returns an object containing the store's
606
- selectors pre-bound to state so that you only need to supply additional arguments,
607
- and modified so that they return promises that resolve to their eventual values,
608
- after any resolvers have ran.
610
+ Given a store descriptor, returns an object containing the store's selectors pre-bound to state
611
+ so that you only need to supply additional arguments, and modified so that they return promises
612
+ that resolve to their eventual values, after any resolvers have ran.
609
613
 
610
614
  _Usage_
611
615
 
612
616
  ```js
613
617
  import { resolveSelect } from '@wordpress/data';
618
+ import { store as myCustomStore } from 'my-custom-store';
614
619
 
615
- resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then( console.log );
620
+ resolveSelect( myCustomStore ).getPrice( 'hammer' ).then( console.log );
616
621
  ```
617
622
 
618
623
  _Parameters_
619
624
 
620
- - _storeNameOrDescriptor_ `string|StoreDescriptor`: Unique namespace identifier for the store or the store descriptor.
625
+ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
621
626
 
622
627
  _Returns_
623
628
 
@@ -625,7 +630,7 @@ _Returns_
625
630
 
626
631
  ### select
627
632
 
628
- Given the name or descriptor of a registered store, returns an object of the store's selectors.
633
+ Given a store descriptor, returns an object of the store's selectors.
629
634
  The selector functions are been pre-bound to pass the current state automatically.
630
635
  As a consumer, you need only pass arguments of the selector, if applicable.
631
636
 
@@ -633,13 +638,14 @@ _Usage_
633
638
 
634
639
  ```js
635
640
  import { select } from '@wordpress/data';
641
+ import { store as myCustomStore } from 'my-custom-store';
636
642
 
637
- select( 'my-shop' ).getPrice( 'hammer' );
643
+ select( myCustomStore ).getPrice( 'hammer' );
638
644
  ```
639
645
 
640
646
  _Parameters_
641
647
 
642
- - _storeNameOrDescriptor_ `string|StoreDescriptor`: Unique namespace identifier for the store or the store descriptor.
648
+ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
643
649
 
644
650
  _Returns_
645
651
 
@@ -671,13 +677,13 @@ _Parameters_
671
677
 
672
678
  ### suspendSelect
673
679
 
674
- Given the name of a registered store, returns an object containing the store's
675
- selectors pre-bound to state so that you only need to supply additional arguments,
676
- and modified so that they throw promises in case the selector is not resolved yet.
680
+ Given a store descriptor, returns an object containing the store's selectors pre-bound to state
681
+ so that you only need to supply additional arguments, and modified so that they throw promises
682
+ in case the selector is not resolved yet.
677
683
 
678
684
  _Parameters_
679
685
 
680
- - _storeNameOrDescriptor_ `string|StoreDescriptor`: Unique namespace identifier for the store or the store descriptor.
686
+ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
681
687
 
682
688
  _Returns_
683
689
 
@@ -709,6 +715,7 @@ action.
709
715
  ```jsx
710
716
  import { useDispatch, useSelect } from '@wordpress/data';
711
717
  import { useCallback } from '@wordpress/element';
718
+ import { store as myCustomStore } from 'my-custom-store';
712
719
 
713
720
  function Button( { onClick, children } ) {
714
721
  return (
@@ -720,10 +727,10 @@ function Button( { onClick, children } ) {
720
727
 
721
728
  const SaleButton = ( { children } ) => {
722
729
  const { stockNumber } = useSelect(
723
- ( select ) => select( 'my-shop' ).getStockNumber(),
730
+ ( select ) => select( myCustomStore ).getStockNumber(),
724
731
  []
725
732
  );
726
- const { startSale } = useDispatch( 'my-shop' );
733
+ const { startSale } = useDispatch( myCustomStore );
727
734
  const onClick = useCallback( () => {
728
735
  const discountPercent = stockNumber > 50 ? 10 : 20;
729
736
  startSale( discountPercent );
@@ -795,11 +802,12 @@ _Usage_
795
802
 
796
803
  ```js
797
804
  import { useSelect } from '@wordpress/data';
805
+ import { store as myCustomStore } from 'my-custom-store';
798
806
 
799
807
  function HammerPriceDisplay( { currency } ) {
800
808
  const price = useSelect(
801
809
  ( select ) => {
802
- return select( 'my-shop' ).getPrice( 'hammer', currency );
810
+ return select( myCustomStore ).getPrice( 'hammer', currency );
803
811
  },
804
812
  [ currency ]
805
813
  );
@@ -828,9 +836,10 @@ function because your component won't re-render on a data change.**
828
836
 
829
837
  ```js
830
838
  import { useSelect } from '@wordpress/data';
839
+ import { store as myCustomStore } from 'my-custom-store';
831
840
 
832
841
  function Paste( { children } ) {
833
- const { getSettings } = useSelect( 'my-shop' );
842
+ const { getSettings } = useSelect( myCustomStore );
834
843
  function onPaste() {
835
844
  // Do something with the settings.
836
845
  const settings = getSettings();
@@ -879,9 +888,10 @@ function Button( { onClick, children } ) {
879
888
  }
880
889
 
881
890
  import { withDispatch } from '@wordpress/data';
891
+ import { store as myCustomStore } from 'my-custom-store';
882
892
 
883
893
  const SaleButton = withDispatch( ( dispatch, ownProps ) => {
884
- const { startSale } = dispatch( 'my-shop' );
894
+ const { startSale } = dispatch( myCustomStore );
885
895
  const { discountPercent } = ownProps;
886
896
 
887
897
  return {
@@ -919,11 +929,12 @@ function Button( { onClick, children } ) {
919
929
  }
920
930
 
921
931
  import { withDispatch } from '@wordpress/data';
932
+ import { store as myCustomStore } from 'my-custom-store';
922
933
 
923
934
  const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
924
935
  // Stock number changes frequently.
925
- const { getStockNumber } = select( 'my-shop' );
926
- const { startSale } = dispatch( 'my-shop' );
936
+ const { getStockNumber } = select( myCustomStore );
937
+ const { startSale } = dispatch( myCustomStore );
927
938
  return {
928
939
  onClick() {
929
940
  const discountPercent = getStockNumber() > 50 ? 10 : 20;
@@ -971,6 +982,7 @@ _Usage_
971
982
 
972
983
  ```js
973
984
  import { withSelect } from '@wordpress/data';
985
+ import { store as myCustomStore } from 'my-custom-store';
974
986
 
975
987
  function PriceDisplay( { price, currency } ) {
976
988
  return new Intl.NumberFormat( 'en-US', {
@@ -980,7 +992,7 @@ function PriceDisplay( { price, currency } ) {
980
992
  }
981
993
 
982
994
  const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
983
- const { getPrice } = select( 'my-shop' );
995
+ const { getPrice } = select( myCustomStore );
984
996
  const { currency } = ownProps;
985
997
 
986
998
  return {
@@ -25,10 +25,11 @@ const AsyncModeConsumer = Consumer;
25
25
  *
26
26
  * ```js
27
27
  * import { useSelect, AsyncModeProvider } from '@wordpress/data';
28
+ * import { store as blockEditorStore } from '@wordpress/block-editor';
28
29
  *
29
30
  * function BlockCount() {
30
31
  * const count = useSelect( ( select ) => {
31
- * return select( 'core/block-editor' ).getBlockCount()
32
+ * return select( blockEditorStore ).getBlockCount()
32
33
  * }, [] );
33
34
  *
34
35
  * return count;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/context.js"],"names":["Context","Consumer","Provider","AsyncModeConsumer"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,OAAO,GAAG,4BAAe,KAAf,CAAhB;;AAEP,MAAM;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,IAAyBF,OAA/B;AAEO,MAAMG,iBAAiB,GAAGF,QAA1B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;eACeC,Q","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( 'core/block-editor' ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {WPComponent} The component to be rendered.\n */\nexport default Provider;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/context.js"],"names":["Context","Consumer","Provider","AsyncModeConsumer"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,OAAO,GAAG,4BAAe,KAAf,CAAhB;;AAEP,MAAM;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,IAAyBF,OAA/B;AAEO,MAAMG,iBAAiB,GAAGF,QAA1B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;eACeC,Q","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n * import { store as blockEditorStore } from '@wordpress/block-editor';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( blockEditorStore ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {WPComponent} The component to be rendered.\n */\nexport default Provider;\n"]}
@@ -35,6 +35,7 @@ var _useRegistry = _interopRequireDefault(require("../registry-provider/use-regi
35
35
  * ```jsx
36
36
  * import { useDispatch, useSelect } from '@wordpress/data';
37
37
  * import { useCallback } from '@wordpress/element';
38
+ * import { store as myCustomStore } from 'my-custom-store';
38
39
  *
39
40
  * function Button( { onClick, children } ) {
40
41
  * return <button type="button" onClick={ onClick }>{ children }</button>
@@ -42,10 +43,10 @@ var _useRegistry = _interopRequireDefault(require("../registry-provider/use-regi
42
43
  *
43
44
  * const SaleButton = ( { children } ) => {
44
45
  * const { stockNumber } = useSelect(
45
- * ( select ) => select( 'my-shop' ).getStockNumber(),
46
+ * ( select ) => select( myCustomStore ).getStockNumber(),
46
47
  * []
47
48
  * );
48
- * const { startSale } = useDispatch( 'my-shop' );
49
+ * const { startSale } = useDispatch( myCustomStore );
49
50
  * const onClick = useCallback( () => {
50
51
  * const discountPercent = stockNumber > 50 ? 10: 20;
51
52
  * startSale( discountPercent );
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch.js"],"names":["useDispatch","storeNameOrDescriptor","dispatch"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAKC,qBAAF,IAA6B;AAChD,QAAM;AAAEC,IAAAA;AAAF,MAAe,2BAArB;AACA,SAAOD,qBAAqB,KAAK,KAAK,CAA/B,GACJC,QADI,GAEJA,QAAQ,CAAED,qBAAF,CAFX;AAGA,CALD;;eAOeD,W","sourcesContent":["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @param {string|StoreDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n *\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>\n * }\n *\n * const SaleButton = ( { children } ) => {\n * const { stockNumber } = useSelect(\n * ( select ) => select( 'my-shop' ).getStockNumber(),\n * []\n * );\n * const { startSale } = useDispatch( 'my-shop' );\n * const onClick = useCallback( () => {\n * const discountPercent = stockNumber > 50 ? 10: 20;\n * startSale( discountPercent );\n * }, [ stockNumber ] );\n * return <Button onClick={ onClick }>{ children }</Button>\n * }\n *\n * // Rendered somewhere in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n * @return {Function} A custom react hook.\n */\nconst useDispatch = ( storeNameOrDescriptor ) => {\n\tconst { dispatch } = useRegistry();\n\treturn storeNameOrDescriptor === void 0\n\t\t? dispatch\n\t\t: dispatch( storeNameOrDescriptor );\n};\n\nexport default useDispatch;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch.js"],"names":["useDispatch","storeNameOrDescriptor","dispatch"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAKC,qBAAF,IAA6B;AAChD,QAAM;AAAEC,IAAAA;AAAF,MAAe,2BAArB;AACA,SAAOD,qBAAqB,KAAK,KAAK,CAA/B,GACJC,QADI,GAEJA,QAAQ,CAAED,qBAAF,CAFX;AAGA,CALD;;eAOeD,W","sourcesContent":["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @param {string|StoreDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>\n * }\n *\n * const SaleButton = ( { children } ) => {\n * const { stockNumber } = useSelect(\n * ( select ) => select( myCustomStore ).getStockNumber(),\n * []\n * );\n * const { startSale } = useDispatch( myCustomStore );\n * const onClick = useCallback( () => {\n * const discountPercent = stockNumber > 50 ? 10: 20;\n * startSale( discountPercent );\n * }, [ stockNumber ] );\n * return <Button onClick={ onClick }>{ children }</Button>\n * }\n *\n * // Rendered somewhere in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n * @return {Function} A custom react hook.\n */\nconst useDispatch = ( storeNameOrDescriptor ) => {\n\tconst { dispatch } = useRegistry();\n\treturn storeNameOrDescriptor === void 0\n\t\t? dispatch\n\t\t: dispatch( storeNameOrDescriptor );\n};\n\nexport default useDispatch;\n"]}
@@ -73,10 +73,11 @@ const renderQueue = (0, _priorityQueue.createQueue)();
73
73
  * @example
74
74
  * ```js
75
75
  * import { useSelect } from '@wordpress/data';
76
+ * import { store as myCustomStore } from 'my-custom-store';
76
77
  *
77
78
  * function HammerPriceDisplay( { currency } ) {
78
79
  * const price = useSelect( ( select ) => {
79
- * return select( 'my-shop' ).getPrice( 'hammer', currency )
80
+ * return select( myCustomStore ).getPrice( 'hammer', currency );
80
81
  * }, [ currency ] );
81
82
  * return new Intl.NumberFormat( 'en-US', {
82
83
  * style: 'currency',
@@ -103,9 +104,10 @@ const renderQueue = (0, _priorityQueue.createQueue)();
103
104
  *
104
105
  * ```js
105
106
  * import { useSelect } from '@wordpress/data';
107
+ * import { store as myCustomStore } from 'my-custom-store';
106
108
  *
107
109
  * function Paste( { children } ) {
108
- * const { getSettings } = useSelect( 'my-shop' );
110
+ * const { getSettings } = useSelect( myCustomStore );
109
111
  * function onPaste() {
110
112
  * // Do something with the settings.
111
113
  * const settings = getSettings();
@@ -242,6 +244,7 @@ function useSelect(mapSelect, deps) {
242
244
  // We're passing these in from the calling function and want to make sure we're
243
245
  // examining every individual value inside the `deps` array.
244
246
  }, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]);
247
+ (0, _element.useDebugValue)(mapOutput);
245
248
  return hasMappingFunction ? mapOutput : registry.select(mapSelect);
246
249
  }
247
250
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe","cancel","useSuspenseSelect","suspendSelect","mapOutputError"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAAMC,kBAAkB,GAAG,eAAe,OAAOF,SAAjD,CADoD,CAGpD;AACA;AACA;;AACA,MAAK,CAAEE,kBAAP,EAA4B;AAC3BD,IAAAA,IAAI,GAAG,EAAP;AACA,GARmD,CAUpD;AACA;AACA;AACA;AACA;;;AACA,QAAME,cAAc,GAAG,0BACtBD,kBAAkB,GAAGF,SAAH,GAAeH,IADX,EAEtBI,IAFsB,CAAvB;;AAIA,QAAMG,UAAU,GAAGF,kBAAkB,GAAGC,cAAH,GAAoB,IAAzD;;AAEA,QAAME,QAAQ,GAAG,2BAAjB;AACA,QAAMC,OAAO,G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AAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA9C,MAAAA,WAAW,CAAC+C,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD;AAMA,GA5CD,EA4CG,CAAEd,QAAF,EAAYQ,UAAZ,EAAwBI,eAAxB,CA5CH;;AA8CA,MAAK+B,cAAL,EAAsB;AACrB,UAAMA,cAAN;AACA;;AAED,SAAO9B,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,Selectors\n */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template T\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\tconst _mapSelect = useCallback( mapSelect, deps );\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the `mapSelect` function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.suspendSelect, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput = latestMapOutput.current;\n\tlet mapOutputError = latestMapOutputError.current;\n\n\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\n\tif ( hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode ) {\n\t\ttry {\n\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t} catch ( error ) {\n\t\t\tmapOutputError = error;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = mapOutputError;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t}, [ registry, wrapSelect, depsChangedFlag ] );\n\n\tif ( mapOutputError ) {\n\t\tthrow mapOutputError;\n\t}\n\n\treturn mapOutput;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe","cancel","useSuspenseSelect","suspendSelect","mapOutputError"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AAOA;;AACA;;AAKA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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;AACA,OAPD,CAOE,OAAQZ,KAAR,EAAgB;AACjBb,QAAAA,oBAAoB,CAACQ,OAArB,GAA+BK,KAA/B;AACA;;AAEDQ,MAAAA,WAAW;AACX,KAbD;;AAeA,UAAMK,QAAQ,GAAG,MAAM;AACtB,UAAK,CAAEH,SAAS,CAACf,OAAjB,EAA2B;AAC1B;AACA;;AAED,UAAKV,aAAa,CAACU,OAAnB,EAA6B;AAC5BrB,QAAAA,WAAW,CAACwC,GAAZ,CAAiBR,YAAjB,EAA+BK,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAVD,CAhBgC,CA4BhC;AACA;;;AACAA,IAAAA,aAAa;AAEb,UAAMI,aAAa,GAAG3B,eAAe,CAACO,OAAhB,CAAwBqB,GAAxB,CAA+BC,SAAF,IAClDpC,QAAQ,CAACqC,wBAAT,CAAmCD,SAAnC,EAA8CJ,QAA9C,CADqB,CAAtB;AAIAH,IAAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA9C,MAAAA,WAAW,CAAC+C,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD;AAMA,GA5CD,EA4CG,CAAEd,QAAF,EAAYQ,UAAZ,EAAwBI,eAAxB,CA5CH;;AA8CA,MAAK+B,cAAL,EAAsB;AACrB,UAAMA,cAAN;AACA;;AAED,SAAO9B,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,Selectors\n */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template T\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\tuseDebugValue( mapOutput );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\tconst _mapSelect = useCallback( mapSelect, deps );\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the `mapSelect` function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.suspendSelect, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput = latestMapOutput.current;\n\tlet mapOutputError = latestMapOutputError.current;\n\n\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\n\tif ( hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode ) {\n\t\ttry {\n\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t} catch ( error ) {\n\t\t\tmapOutputError = error;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = mapOutputError;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t}, [ registry, wrapSelect, depsChangedFlag ] );\n\n\tif ( mapOutputError ) {\n\t\tthrow mapOutputError;\n\t}\n\n\treturn mapOutput;\n}\n"]}
@@ -41,9 +41,10 @@ var _useDispatch = require("../use-dispatch");
41
41
  * }
42
42
  *
43
43
  * import { withDispatch } from '@wordpress/data';
44
+ * import { store as myCustomStore } from 'my-custom-store';
44
45
  *
45
46
  * const SaleButton = withDispatch( ( dispatch, ownProps ) => {
46
- * const { startSale } = dispatch( 'my-shop' );
47
+ * const { startSale } = dispatch( myCustomStore );
47
48
  * const { discountPercent } = ownProps;
48
49
  *
49
50
  * return {
@@ -78,11 +79,12 @@ var _useDispatch = require("../use-dispatch");
78
79
  * }
79
80
  *
80
81
  * import { withDispatch } from '@wordpress/data';
82
+ * import { store as myCustomStore } from 'my-custom-store';
81
83
  *
82
84
  * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
83
85
  * // Stock number changes frequently.
84
- * const { getStockNumber } = select( 'my-shop' );
85
- * const { startSale } = dispatch( 'my-shop' );
86
+ * const { getStockNumber } = select( myCustomStore );
87
+ * const { startSale } = dispatch( myCustomStore );
86
88
  * return {
87
89
  * onClick() {
88
90
  * const discountPercent = getStockNumber() > 50 ? 10 : 20;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/with-dispatch/index.js"],"names":["withDispatch","mapDispatchToProps","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAKC,kBAAF,IACpB,yCACGC,gBAAF,IAA0BC,QAAF,IAAgB;AACvC,QAAMC,WAAW,GAAG,CAAEC,QAAF,EAAYC,QAAZ,KACnBL,kBAAkB,CAAEI,QAAF,EAAYF,QAAZ,EAAsBG,QAAtB,CADnB;;AAEA,QAAMC,aAAa,GAAG,qCAAoBH,WAApB,EAAiC,EAAjC,CAAtB;AACA,SAAO,4BAAC,gBAAD,6BAAuBD,QAAvB,EAAuCI,aAAvC,EAAP;AACA,CANF,EAOC,cAPD,CADD;;eAWeP,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( 'my-shop' );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( 'my-shop' );\n * const { startSale } = dispatch( 'my-shop' );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {WPComponent} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/with-dispatch/index.js"],"names":["withDispatch","mapDispatchToProps","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAKC,kBAAF,IACpB,yCACGC,gBAAF,IAA0BC,QAAF,IAAgB;AACvC,QAAMC,WAAW,GAAG,CAAEC,QAAF,EAAYC,QAAZ,KACnBL,kBAAkB,CAAEI,QAAF,EAAYF,QAAZ,EAAsBG,QAAtB,CADnB;;AAEA,QAAMC,aAAa,GAAG,qCAAoBH,WAApB,EAAiC,EAAjC,CAAtB;AACA,SAAO,4BAAC,gBAAD,6BAAuBD,QAAvB,EAAuCI,aAAvC,EAAP;AACA,CANF,EAOC,cAPD,CADD;;eAWeP,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {WPComponent} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"]}
@@ -34,6 +34,7 @@ var _useSelect = _interopRequireDefault(require("../use-select"));
34
34
  * @example
35
35
  * ```js
36
36
  * import { withSelect } from '@wordpress/data';
37
+ * import { store as myCustomStore } from 'my-custom-store';
37
38
  *
38
39
  * function PriceDisplay( { price, currency } ) {
39
40
  * return new Intl.NumberFormat( 'en-US', {
@@ -43,7 +44,7 @@ var _useSelect = _interopRequireDefault(require("../use-select"));
43
44
  * }
44
45
  *
45
46
  * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
46
- * const { getPrice } = select( 'my-shop' );
47
+ * const { getPrice } = select( myCustomStore );
47
48
  * const { currency } = ownProps;
48
49
  *
49
50
  * return {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/with-select/index.js"],"names":["withSelect","mapSelectToProps","WrappedComponent","ownProps","mapSelect","select","registry","mergeProps"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,UAAU,GAAKC,gBAAF,IAClB,yCACGC,gBAAF,IACC,mBAAQC,QAAF,IAAgB;AACrB,QAAMC,SAAS,GAAG,CAAEC,MAAF,EAAUC,QAAV,KACjBL,gBAAgB,CAAEI,MAAF,EAAUF,QAAV,EAAoBG,QAApB,CADjB;;AAEA,QAAMC,UAAU,GAAG,wBAAWH,SAAX,CAAnB;AACA,SAAO,4BAAC,gBAAD,6BAAuBD,QAAvB,EAAuCI,UAAvC,EAAP;AACA,CALD,CAFF,EAQC,YARD,CADD;;eAYeP,U","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( 'my-shop' );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {WPComponent} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/with-select/index.js"],"names":["withSelect","mapSelectToProps","WrappedComponent","ownProps","mapSelect","select","registry","mergeProps"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,UAAU,GAAKC,gBAAF,IAClB,yCACGC,gBAAF,IACC,mBAAQC,QAAF,IAAgB;AACrB,QAAMC,SAAS,GAAG,CAAEC,MAAF,EAAUC,QAAV,KACjBL,gBAAgB,CAAEI,MAAF,EAAUF,QAAV,EAAoBG,QAApB,CADjB;;AAEA,QAAMC,UAAU,GAAG,wBAAWH,SAAX,CAAnB;AACA,SAAO,4BAAC,gBAAD,6BAAuBD,QAAvB,EAAuCI,UAAvC,EAAP;AACA,CALD,CAFF,EAQC,YARD,CADD;;eAYeP,U","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {WPComponent} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"]}
package/build/controls.js CHANGED
@@ -5,14 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.controls = exports.builtinControls = void 0;
7
7
 
8
- var _lodash = require("lodash");
9
-
10
8
  var _factory = require("./factory");
11
9
 
12
- /**
13
- * External dependencies
14
- */
15
-
16
10
  /**
17
11
  * Internal dependencies
18
12
  */
@@ -21,6 +15,10 @@ var _factory = require("./factory");
21
15
  const SELECT = '@@data/SELECT';
22
16
  const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
23
17
  const DISPATCH = '@@data/DISPATCH';
18
+
19
+ function isObject(object) {
20
+ return object !== null && typeof object === 'object';
21
+ }
24
22
  /**
25
23
  * Dispatches a control action for triggering a synchronous registry select.
26
24
  *
@@ -45,6 +43,7 @@ const DISPATCH = '@@data/DISPATCH';
45
43
  * @return {Object} The control descriptor.
46
44
  */
47
45
 
46
+
48
47
  function select(storeNameOrDescriptor, selectorName) {
49
48
  for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
50
49
  args[_key - 2] = arguments[_key];
@@ -52,7 +51,7 @@ function select(storeNameOrDescriptor, selectorName) {
52
51
 
53
52
  return {
54
53
  type: SELECT,
55
- storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
54
+ storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
56
55
  selectorName,
57
56
  args
58
57
  };
@@ -90,7 +89,7 @@ function resolveSelect(storeNameOrDescriptor, selectorName) {
90
89
 
91
90
  return {
92
91
  type: RESOLVE_SELECT,
93
- storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
92
+ storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
94
93
  selectorName,
95
94
  args
96
95
  };
@@ -124,7 +123,7 @@ function dispatch(storeNameOrDescriptor, actionName) {
124
123
 
125
124
  return {
126
125
  type: DISPATCH,
127
- storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
126
+ storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
128
127
  actionName,
129
128
  args
130
129
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,EAAgE;AAAA,oCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAC/D,SAAO;AACNC,IAAAA,IAAI,EAAEP,MADA;AAENQ,IAAAA,QAAQ,EAAE,sBAAUJ,qBAAV,IACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNC,IAAAA,YALM;AAMNC,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,aAAT,CAAwBN,qBAAxB,EAA+CC,YAA/C,EAAuE;AAAA,qCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AACtE,SAAO;AACNC,IAAAA,IAAI,EAAEN,cADA;AAENO,IAAAA,QAAQ,EAAE,sBAAUJ,qBAAV,IACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNC,IAAAA,YALM;AAMNC,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA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,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CADD;AAAA,GAFY;AAlBgB,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport { isObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","isObject","object","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;;AAEA,SAASC,QAAT,CAAmBC,MAAnB,EAA4B;AAC3B,SAAOA,MAAM,KAAK,IAAX,IAAmB,OAAOA,MAAP,KAAkB,QAA5C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,EAAgE;AAAA,oCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAC/D,SAAO;AACNC,IAAAA,IAAI,EAAET,MADA;AAENU,IAAAA,QAAQ,EAAEP,QAAQ,CAAEG,qBAAF,CAAR,GACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNC,IAAAA,YALM;AAMNC,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,aAAT,CAAwBN,qBAAxB,EAA+CC,YAA/C,EAAuE;AAAA,qCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AACtE,SAAO;AACNC,IAAAA,IAAI,EAAER,cADA;AAENS,IAAAA,QAAQ,EAAEP,QAAQ,CAAEG,qBAAF,CAAR,GACPA,qBAAqB,CAACK,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AAF,IACC;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYI,MAAAA,UAAZ;AAAwBN,MAAAA;AAAxB,KAAF;AAAA,WACCS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CADD;AAAA,GAFY;AAlBgB,CAAxB","sourcesContent":["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isObject( object ) {\n\treturn object !== null && typeof object === 'object';\n}\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}