@wordpress/data 6.10.0 → 6.13.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.
- package/CHANGELOG.md +10 -0
- package/README.md +55 -36
- package/build/components/async-mode-provider/context.js +2 -1
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +3 -2
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +32 -19
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +5 -3
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +2 -1
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +8 -9
- package/build/controls.js.map +1 -1
- package/build/factory.js +5 -2
- package/build/factory.js.map +1 -1
- package/build/index.js +26 -20
- package/build/index.js.map +1 -1
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +14 -7
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +21 -16
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +2 -1
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +3 -2
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +33 -20
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +5 -3
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +2 -1
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +5 -5
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +5 -2
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +26 -20
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/redux-store/index.js +14 -7
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +17 -12
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js.map +1 -1
- package/build-types/components/async-mode-provider/context.d.ts +5 -0
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -0
- package/build-types/components/async-mode-provider/index.d.ts +3 -0
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -0
- package/build-types/components/async-mode-provider/use-async-mode.d.ts +2 -0
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -0
- package/build-types/components/registry-provider/context.d.ts +36 -0
- package/build-types/components/registry-provider/context.d.ts.map +1 -0
- package/build-types/components/registry-provider/index.d.ts +3 -0
- package/build-types/components/registry-provider/index.d.ts.map +1 -0
- package/build-types/components/registry-provider/use-registry.d.ts +41 -0
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -0
- package/build-types/components/use-dispatch/index.d.ts +3 -0
- package/build-types/components/use-dispatch/index.d.ts.map +1 -0
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +17 -0
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -0
- package/build-types/components/use-dispatch/use-dispatch.d.ts +50 -0
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -0
- package/build-types/components/use-select/index.d.ts +99 -0
- package/build-types/components/use-select/index.d.ts.map +1 -0
- package/build-types/components/with-dispatch/index.d.ts +84 -0
- package/build-types/components/with-dispatch/index.d.ts.map +1 -0
- package/build-types/components/with-registry/index.d.ts +11 -0
- package/build-types/components/with-registry/index.d.ts.map +1 -0
- package/build-types/components/with-select/index.d.ts +43 -0
- package/build-types/components/with-select/index.d.ts.map +1 -0
- package/build-types/controls.d.ts +83 -0
- package/build-types/controls.d.ts.map +1 -0
- package/build-types/default-registry.d.ts +3 -0
- package/build-types/default-registry.d.ts.map +1 -0
- package/build-types/factory.d.ts +63 -0
- package/build-types/factory.d.ts.map +1 -0
- package/build-types/index.d.ts +156 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/plugins/index.d.ts +2 -0
- package/build-types/plugins/index.d.ts.map +1 -0
- package/build-types/plugins/persistence/index.d.ts +41 -0
- package/build-types/plugins/persistence/index.d.ts.map +1 -0
- package/build-types/plugins/persistence/storage/default.d.ts +3 -0
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -0
- package/build-types/plugins/persistence/storage/object.d.ts +10 -0
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -0
- package/build-types/redux-store/index.d.ts +29 -0
- package/build-types/redux-store/index.d.ts.map +1 -0
- package/build-types/redux-store/metadata/utils.d.ts.map +1 -1
- package/build-types/redux-store/thunk-middleware.d.ts +2 -0
- package/build-types/redux-store/thunk-middleware.d.ts.map +1 -0
- package/build-types/registry.d.ts +56 -0
- package/build-types/registry.d.ts.map +1 -0
- package/build-types/resolvers-cache-middleware.d.ts +15 -0
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -0
- package/build-types/store/index.d.ts +23 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/types.d.ts +18 -1
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/components/async-mode-provider/context.js +2 -1
- package/src/components/use-dispatch/use-dispatch.js +3 -2
- package/src/components/use-select/index.js +37 -20
- package/src/components/use-select/test/suspense.js +15 -11
- package/src/components/with-dispatch/index.js +5 -3
- package/src/components/with-dispatch/test/index.js +4 -5
- package/src/components/with-registry/index.js +8 -7
- package/src/components/with-select/index.js +2 -1
- package/src/components/with-select/test/index.js +12 -18
- package/src/controls.js +20 -16
- package/src/factory.js +5 -2
- package/src/index.js +26 -20
- package/src/plugins/persistence/index.js +2 -4
- package/src/redux-store/index.js +22 -12
- package/src/redux-store/metadata/test/utils.js +1 -2
- package/src/redux-store/metadata/utils.ts +24 -24
- package/src/redux-store/test/index.js +4 -3
- package/src/registry.js +17 -12
- package/src/resolvers-cache-middleware.js +33 -34
- package/src/store/index.js +10 -6
- package/src/test/registry.js +19 -23
- package/src/types.ts +39 -6
- package/tsconfig.json +4 -2
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 6.13.0 (2022-07-13)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Use `useDebugValue` in `useSelect` to better display data in React DevTools ([#42225](https://github.com/WordPress/gutenberg/pull/42225)).
|
|
10
|
+
|
|
11
|
+
## 6.12.0 (2022-06-29)
|
|
12
|
+
|
|
13
|
+
## 6.11.0 (2022-06-15)
|
|
14
|
+
|
|
5
15
|
## 6.10.0 (2022-06-01)
|
|
6
16
|
|
|
7
17
|
## 6.9.0 (2022-05-18)
|
package/README.md
CHANGED
|
@@ -174,11 +174,16 @@ const reduxStore = createStore();
|
|
|
174
174
|
|
|
175
175
|
const boundSelectors = mapValues(
|
|
176
176
|
existingSelectors,
|
|
177
|
-
( selector ) =>
|
|
177
|
+
( selector ) =>
|
|
178
|
+
( ...args ) =>
|
|
179
|
+
selector( reduxStore.getState(), ...args )
|
|
178
180
|
);
|
|
179
181
|
|
|
180
|
-
const boundActions = mapValues(
|
|
181
|
-
|
|
182
|
+
const boundActions = mapValues(
|
|
183
|
+
existingActions,
|
|
184
|
+
( action ) =>
|
|
185
|
+
( ...args ) =>
|
|
186
|
+
reduxStore.dispatch( action( ...args ) )
|
|
182
187
|
);
|
|
183
188
|
|
|
184
189
|
const genericStore = {
|
|
@@ -273,10 +278,11 @@ _Usage_
|
|
|
273
278
|
|
|
274
279
|
```js
|
|
275
280
|
import { useSelect, AsyncModeProvider } from '@wordpress/data';
|
|
281
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
276
282
|
|
|
277
283
|
function BlockCount() {
|
|
278
284
|
const count = useSelect( ( select ) => {
|
|
279
|
-
return select(
|
|
285
|
+
return select( blockEditorStore ).getBlockCount();
|
|
280
286
|
}, [] );
|
|
281
287
|
|
|
282
288
|
return count;
|
|
@@ -369,11 +375,11 @@ const store = createReduxStore( 'demo', {
|
|
|
369
375
|
_Parameters_
|
|
370
376
|
|
|
371
377
|
- _key_ `string`: Unique namespace identifier.
|
|
372
|
-
- _options_ `ReduxStoreConfig
|
|
378
|
+
- _options_ `ReduxStoreConfig<State,Actions,Selectors>`: Registered store options, with properties describing reducer, actions, selectors, and resolvers.
|
|
373
379
|
|
|
374
380
|
_Returns_
|
|
375
381
|
|
|
376
|
-
- `StoreDescriptor
|
|
382
|
+
- `StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>`: Store Object.
|
|
377
383
|
|
|
378
384
|
### createRegistry
|
|
379
385
|
|
|
@@ -431,7 +437,9 @@ that allows to select data from the store's `state`, a registry selector
|
|
|
431
437
|
has signature:
|
|
432
438
|
|
|
433
439
|
```js
|
|
434
|
-
( select ) =>
|
|
440
|
+
( select ) =>
|
|
441
|
+
( state, ...selectorArgs ) =>
|
|
442
|
+
result;
|
|
435
443
|
```
|
|
436
444
|
|
|
437
445
|
that supports also selecting from other registered stores.
|
|
@@ -439,15 +447,18 @@ that supports also selecting from other registered stores.
|
|
|
439
447
|
_Usage_
|
|
440
448
|
|
|
441
449
|
```js
|
|
450
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
451
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
452
|
+
|
|
442
453
|
const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
|
|
443
|
-
return select(
|
|
454
|
+
return select( editorStore ).getCurrentPostId();
|
|
444
455
|
} );
|
|
445
456
|
|
|
446
457
|
const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
|
|
447
458
|
// calling another registry selector just like any other function
|
|
448
459
|
const postType = getCurrentPostType( state );
|
|
449
460
|
const postId = getCurrentPostId( state );
|
|
450
|
-
return select(
|
|
461
|
+
return select( coreStore ).getEntityRecordEdits(
|
|
451
462
|
'postType',
|
|
452
463
|
postType,
|
|
453
464
|
postId
|
|
@@ -470,7 +481,7 @@ _Returns_
|
|
|
470
481
|
|
|
471
482
|
### dispatch
|
|
472
483
|
|
|
473
|
-
Given
|
|
484
|
+
Given a store descriptor, returns an object of the store's action creators.
|
|
474
485
|
Calling an action creator will cause it to be dispatched, updating the state value accordingly.
|
|
475
486
|
|
|
476
487
|
Note: Action creators returned by the dispatch will return a promise when
|
|
@@ -480,13 +491,14 @@ _Usage_
|
|
|
480
491
|
|
|
481
492
|
```js
|
|
482
493
|
import { dispatch } from '@wordpress/data';
|
|
494
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
483
495
|
|
|
484
|
-
dispatch(
|
|
496
|
+
dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
|
|
485
497
|
```
|
|
486
498
|
|
|
487
499
|
_Parameters_
|
|
488
500
|
|
|
489
|
-
- _storeNameOrDescriptor_ `string
|
|
501
|
+
- _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
|
|
490
502
|
|
|
491
503
|
_Returns_
|
|
492
504
|
|
|
@@ -595,22 +607,22 @@ example.
|
|
|
595
607
|
|
|
596
608
|
### resolveSelect
|
|
597
609
|
|
|
598
|
-
Given
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
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.
|
|
602
613
|
|
|
603
614
|
_Usage_
|
|
604
615
|
|
|
605
616
|
```js
|
|
606
617
|
import { resolveSelect } from '@wordpress/data';
|
|
618
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
607
619
|
|
|
608
|
-
resolveSelect(
|
|
620
|
+
resolveSelect( myCustomStore ).getPrice( 'hammer' ).then( console.log );
|
|
609
621
|
```
|
|
610
622
|
|
|
611
623
|
_Parameters_
|
|
612
624
|
|
|
613
|
-
- _storeNameOrDescriptor_ `string
|
|
625
|
+
- _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
|
|
614
626
|
|
|
615
627
|
_Returns_
|
|
616
628
|
|
|
@@ -618,7 +630,7 @@ _Returns_
|
|
|
618
630
|
|
|
619
631
|
### select
|
|
620
632
|
|
|
621
|
-
Given
|
|
633
|
+
Given a store descriptor, returns an object of the store's selectors.
|
|
622
634
|
The selector functions are been pre-bound to pass the current state automatically.
|
|
623
635
|
As a consumer, you need only pass arguments of the selector, if applicable.
|
|
624
636
|
|
|
@@ -626,13 +638,14 @@ _Usage_
|
|
|
626
638
|
|
|
627
639
|
```js
|
|
628
640
|
import { select } from '@wordpress/data';
|
|
641
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
629
642
|
|
|
630
|
-
select(
|
|
643
|
+
select( myCustomStore ).getPrice( 'hammer' );
|
|
631
644
|
```
|
|
632
645
|
|
|
633
646
|
_Parameters_
|
|
634
647
|
|
|
635
|
-
- _storeNameOrDescriptor_ `string
|
|
648
|
+
- _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
|
|
636
649
|
|
|
637
650
|
_Returns_
|
|
638
651
|
|
|
@@ -664,13 +677,13 @@ _Parameters_
|
|
|
664
677
|
|
|
665
678
|
### suspendSelect
|
|
666
679
|
|
|
667
|
-
Given
|
|
668
|
-
|
|
669
|
-
|
|
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.
|
|
670
683
|
|
|
671
684
|
_Parameters_
|
|
672
685
|
|
|
673
|
-
- _storeNameOrDescriptor_ `string
|
|
686
|
+
- _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
|
|
674
687
|
|
|
675
688
|
_Returns_
|
|
676
689
|
|
|
@@ -702,6 +715,7 @@ action.
|
|
|
702
715
|
```jsx
|
|
703
716
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
704
717
|
import { useCallback } from '@wordpress/element';
|
|
718
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
705
719
|
|
|
706
720
|
function Button( { onClick, children } ) {
|
|
707
721
|
return (
|
|
@@ -713,10 +727,10 @@ function Button( { onClick, children } ) {
|
|
|
713
727
|
|
|
714
728
|
const SaleButton = ( { children } ) => {
|
|
715
729
|
const { stockNumber } = useSelect(
|
|
716
|
-
( select ) => select(
|
|
730
|
+
( select ) => select( myCustomStore ).getStockNumber(),
|
|
717
731
|
[]
|
|
718
732
|
);
|
|
719
|
-
const { startSale } = useDispatch(
|
|
733
|
+
const { startSale } = useDispatch( myCustomStore );
|
|
720
734
|
const onClick = useCallback( () => {
|
|
721
735
|
const discountPercent = stockNumber > 50 ? 10 : 20;
|
|
722
736
|
startSale( discountPercent );
|
|
@@ -788,11 +802,12 @@ _Usage_
|
|
|
788
802
|
|
|
789
803
|
```js
|
|
790
804
|
import { useSelect } from '@wordpress/data';
|
|
805
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
791
806
|
|
|
792
807
|
function HammerPriceDisplay( { currency } ) {
|
|
793
808
|
const price = useSelect(
|
|
794
809
|
( select ) => {
|
|
795
|
-
return select(
|
|
810
|
+
return select( myCustomStore ).getPrice( 'hammer', currency );
|
|
796
811
|
},
|
|
797
812
|
[ currency ]
|
|
798
813
|
);
|
|
@@ -821,9 +836,10 @@ function because your component won't re-render on a data change.**
|
|
|
821
836
|
|
|
822
837
|
```js
|
|
823
838
|
import { useSelect } from '@wordpress/data';
|
|
839
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
824
840
|
|
|
825
841
|
function Paste( { children } ) {
|
|
826
|
-
const { getSettings } = useSelect(
|
|
842
|
+
const { getSettings } = useSelect( myCustomStore );
|
|
827
843
|
function onPaste() {
|
|
828
844
|
// Do something with the settings.
|
|
829
845
|
const settings = getSettings();
|
|
@@ -834,12 +850,12 @@ function Paste( { children } ) {
|
|
|
834
850
|
|
|
835
851
|
_Parameters_
|
|
836
852
|
|
|
837
|
-
- _mapSelect_ `
|
|
838
|
-
- _deps_ `
|
|
853
|
+
- _mapSelect_ `T`: Function called on every state change. The returned value is exposed to the component implementing this hook. The function receives the `registry.select` method on the first argument and the `registry` on the second argument. When a store key is passed, all selectors for the store will be returned. This is only meant for usage of these selectors in event callbacks, not for data needed to create the element tree.
|
|
854
|
+
- _deps_ `unknown[]`: If provided, this memoizes the mapSelect so the same `mapSelect` is invoked on every state change unless the dependencies change.
|
|
839
855
|
|
|
840
856
|
_Returns_
|
|
841
857
|
|
|
842
|
-
- `
|
|
858
|
+
- `UseSelectReturn<T>`: A custom react hook.
|
|
843
859
|
|
|
844
860
|
### useSuspenseSelect
|
|
845
861
|
|
|
@@ -872,9 +888,10 @@ function Button( { onClick, children } ) {
|
|
|
872
888
|
}
|
|
873
889
|
|
|
874
890
|
import { withDispatch } from '@wordpress/data';
|
|
891
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
875
892
|
|
|
876
893
|
const SaleButton = withDispatch( ( dispatch, ownProps ) => {
|
|
877
|
-
const { startSale } = dispatch(
|
|
894
|
+
const { startSale } = dispatch( myCustomStore );
|
|
878
895
|
const { discountPercent } = ownProps;
|
|
879
896
|
|
|
880
897
|
return {
|
|
@@ -912,11 +929,12 @@ function Button( { onClick, children } ) {
|
|
|
912
929
|
}
|
|
913
930
|
|
|
914
931
|
import { withDispatch } from '@wordpress/data';
|
|
932
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
915
933
|
|
|
916
934
|
const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
|
|
917
935
|
// Stock number changes frequently.
|
|
918
|
-
const { getStockNumber } = select(
|
|
919
|
-
const { startSale } = dispatch(
|
|
936
|
+
const { getStockNumber } = select( myCustomStore );
|
|
937
|
+
const { startSale } = dispatch( myCustomStore );
|
|
920
938
|
return {
|
|
921
939
|
onClick() {
|
|
922
940
|
const discountPercent = getStockNumber() > 50 ? 10 : 20;
|
|
@@ -964,6 +982,7 @@ _Usage_
|
|
|
964
982
|
|
|
965
983
|
```js
|
|
966
984
|
import { withSelect } from '@wordpress/data';
|
|
985
|
+
import { store as myCustomStore } from 'my-custom-store';
|
|
967
986
|
|
|
968
987
|
function PriceDisplay( { price, currency } ) {
|
|
969
988
|
return new Intl.NumberFormat( 'en-US', {
|
|
@@ -973,7 +992,7 @@ function PriceDisplay( { price, currency } ) {
|
|
|
973
992
|
}
|
|
974
993
|
|
|
975
994
|
const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
|
|
976
|
-
const { getPrice } = select(
|
|
995
|
+
const { getPrice } = select( myCustomStore );
|
|
977
996
|
const { currency } = ownProps;
|
|
978
997
|
|
|
979
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(
|
|
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(
|
|
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(
|
|
46
|
+
* ( select ) => select( myCustomStore ).getStockNumber(),
|
|
46
47
|
* []
|
|
47
48
|
* );
|
|
48
|
-
* const { startSale } = useDispatch(
|
|
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(
|
|
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"]}
|
|
@@ -36,7 +36,22 @@ var _useAsyncMode = _interopRequireDefault(require("../async-mode-provider/use-a
|
|
|
36
36
|
const noop = () => {};
|
|
37
37
|
|
|
38
38
|
const renderQueue = (0, _priorityQueue.createQueue)();
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
|
|
41
|
+
* @template C
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
|
|
46
|
+
* @template State,Actions,Selectors
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
|
|
51
|
+
* @template T
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** @typedef {import('../../types').MapSelect} MapSelect */
|
|
40
55
|
|
|
41
56
|
/**
|
|
42
57
|
* Custom react hook for retrieving props from registered selectors.
|
|
@@ -44,28 +59,25 @@ const renderQueue = (0, _priorityQueue.createQueue)();
|
|
|
44
59
|
* In general, this custom React hook follows the
|
|
45
60
|
* [rules of hooks](https://reactjs.org/docs/hooks-rules.html).
|
|
46
61
|
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* element tree.
|
|
58
|
-
* @param {Array} deps If provided, this memoizes the mapSelect so the
|
|
59
|
-
* same `mapSelect` is invoked on every state
|
|
60
|
-
* change unless the dependencies change.
|
|
62
|
+
* @template {MapSelect | StoreDescriptor<any>} T
|
|
63
|
+
* @param {T} mapSelect Function called on every state change. The returned value is
|
|
64
|
+
* exposed to the component implementing this hook. The function
|
|
65
|
+
* receives the `registry.select` method on the first argument
|
|
66
|
+
* and the `registry` on the second argument.
|
|
67
|
+
* When a store key is passed, all selectors for the store will be
|
|
68
|
+
* returned. This is only meant for usage of these selectors in event
|
|
69
|
+
* callbacks, not for data needed to create the element tree.
|
|
70
|
+
* @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is
|
|
71
|
+
* invoked on every state change unless the dependencies change.
|
|
61
72
|
*
|
|
62
73
|
* @example
|
|
63
74
|
* ```js
|
|
64
75
|
* import { useSelect } from '@wordpress/data';
|
|
76
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
65
77
|
*
|
|
66
78
|
* function HammerPriceDisplay( { currency } ) {
|
|
67
79
|
* const price = useSelect( ( select ) => {
|
|
68
|
-
* return select(
|
|
80
|
+
* return select( myCustomStore ).getPrice( 'hammer', currency );
|
|
69
81
|
* }, [ currency ] );
|
|
70
82
|
* return new Intl.NumberFormat( 'en-US', {
|
|
71
83
|
* style: 'currency',
|
|
@@ -92,9 +104,10 @@ const renderQueue = (0, _priorityQueue.createQueue)();
|
|
|
92
104
|
*
|
|
93
105
|
* ```js
|
|
94
106
|
* import { useSelect } from '@wordpress/data';
|
|
107
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
95
108
|
*
|
|
96
109
|
* function Paste( { children } ) {
|
|
97
|
-
* const { getSettings } = useSelect(
|
|
110
|
+
* const { getSettings } = useSelect( myCustomStore );
|
|
98
111
|
* function onPaste() {
|
|
99
112
|
* // Do something with the settings.
|
|
100
113
|
* const settings = getSettings();
|
|
@@ -102,8 +115,7 @@ const renderQueue = (0, _priorityQueue.createQueue)();
|
|
|
102
115
|
* return <div onPaste={ onPaste }>{ children }</div>;
|
|
103
116
|
* }
|
|
104
117
|
* ```
|
|
105
|
-
*
|
|
106
|
-
* @return {Function} A custom react hook.
|
|
118
|
+
* @return {UseSelectReturn<T>} A custom react hook.
|
|
107
119
|
*/
|
|
108
120
|
|
|
109
121
|
function useSelect(mapSelect, deps) {
|
|
@@ -232,6 +244,7 @@ function useSelect(mapSelect, deps) {
|
|
|
232
244
|
// We're passing these in from the calling function and want to make sure we're
|
|
233
245
|
// examining every individual value inside the `deps` array.
|
|
234
246
|
}, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]);
|
|
247
|
+
(0, _element.useDebugValue)(mapOutput);
|
|
235
248
|
return hasMappingFunction ? mapOutput : registry.select(mapSelect);
|
|
236
249
|
}
|
|
237
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;;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;AAC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X,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 { 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/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\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 * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * 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 *\n * @return {Function} 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;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,GAAG,4BAAhB;AAEA,QAAMC,cAAc,GAAG,qBAAQF,QAAR,CAAvB;AACA,QAAMG,eAAe,GAAG,sBAAxB;AACA,QAAMC,aAAa,GAAG,qBAAQH,OAAR,CAAtB;AACA,QAAMI,eAAe,GAAG,sBAAxB;AACA,QAAMC,oBAAoB,GAAG,sBAA7B,CA5BoD,CA8BpD;AACA;;AACA,QAAMC,eAAe,GAAG,qBAAQ,EAAR,CAAxB;AACA,QAAMC,UAAU,GAAG,0BAChBC,QAAF,IACCT,QAAQ,CAACU,6BAAT,CACC,MAAMD,QAAQ,CAAET,QAAQ,CAACW,MAAX,EAAmBX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ACrB,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(
|
|
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(
|
|
85
|
-
* const { startSale } = dispatch(
|
|
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(
|
|
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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/with-registry/index.js"],"names":["withRegistry","OriginalComponent","props","registry"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,yCAClBC,iBAAF,IAA2BC,KAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/with-registry/index.js"],"names":["withRegistry","OriginalComponent","props","registry"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,yCAClBC,iBAAF,IAA2BC,KAAF,IAEvB,4BAAC,kCAAD,QACKC,QAAF,IACD,4BAAC,iBAAD,6BAAwBD,KAAxB;AAAgC,EAAA,QAAQ,EAAGC;AAA3C,GAFF,CAHkB,EASpB,cAToB,CAArB;eAYeH,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {WPComponent} OriginalComponent Original component.\n *\n * @return {WPComponent} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) =>\n\t\t(\n\t\t\t<RegistryConsumer>\n\t\t\t\t{ ( registry ) => (\n\t\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t\t) }\n\t\t\t</RegistryConsumer>\n\t\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"]}
|