@wordpress/data 8.4.0 → 8.6.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 (58) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +0 -8
  3. package/build/components/use-select/index.js +2 -1
  4. package/build/components/use-select/index.js.map +1 -1
  5. package/build/components/with-dispatch/index.js +2 -0
  6. package/build/components/with-dispatch/index.js.map +1 -1
  7. package/build/components/with-select/index.js +2 -0
  8. package/build/components/with-select/index.js.map +1 -1
  9. package/build/index.js +14 -9
  10. package/build/index.js.map +1 -1
  11. package/build/redux-store/index.js +4 -2
  12. package/build/redux-store/index.js.map +1 -1
  13. package/build-module/components/use-select/index.js +2 -1
  14. package/build-module/components/use-select/index.js.map +1 -1
  15. package/build-module/components/with-dispatch/index.js +2 -0
  16. package/build-module/components/with-dispatch/index.js.map +1 -1
  17. package/build-module/components/with-select/index.js +2 -0
  18. package/build-module/components/with-select/index.js.map +1 -1
  19. package/build-module/index.js +6 -6
  20. package/build-module/index.js.map +1 -1
  21. package/build-module/redux-store/index.js +4 -2
  22. package/build-module/redux-store/index.js.map +1 -1
  23. package/build-types/components/use-select/index.d.ts +1 -1
  24. package/build-types/components/use-select/index.d.ts.map +1 -1
  25. package/build-types/components/with-dispatch/index.d.ts +3 -1
  26. package/build-types/components/with-dispatch/index.d.ts.map +1 -1
  27. package/build-types/components/with-select/index.d.ts +3 -1
  28. package/build-types/components/with-select/index.d.ts.map +1 -1
  29. package/build-types/default-registry.d.ts +1 -1
  30. package/build-types/index.d.ts +41 -45
  31. package/build-types/index.d.ts.map +1 -1
  32. package/build-types/plugins/persistence/storage/object.d.ts +0 -3
  33. package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
  34. package/build-types/redux-store/index.d.ts +4 -3
  35. package/build-types/redux-store/index.d.ts.map +1 -1
  36. package/build-types/redux-store/metadata/reducer.d.ts +5 -5
  37. package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
  38. package/build-types/store/index.d.ts +0 -9
  39. package/build-types/store/index.d.ts.map +1 -1
  40. package/build-types/types.d.ts +16 -16
  41. package/build-types/types.d.ts.map +1 -1
  42. package/package.json +9 -9
  43. package/src/components/use-dispatch/test/use-dispatch.js +0 -2
  44. package/src/components/use-select/index.js +2 -1
  45. package/src/components/use-select/test/index.js +0 -2
  46. package/src/components/use-select/test/suspense.js +0 -2
  47. package/src/components/with-dispatch/index.js +2 -0
  48. package/src/components/with-dispatch/test/index.js +0 -2
  49. package/src/components/with-select/index.js +2 -0
  50. package/src/components/with-select/test/index.js +0 -2
  51. package/src/index.js +6 -6
  52. package/src/redux-store/index.js +4 -2
  53. package/src/redux-store/metadata/test/selectors.js +0 -1
  54. package/src/redux-store/test/index.js +0 -2
  55. package/src/test/controls.js +0 -2
  56. package/src/test/privateAPIs.js +0 -13
  57. package/src/test/registry.js +1 -8
  58. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 8.6.0 (2023-03-15)
6
+
7
+ ## 8.5.0 (2023-03-01)
8
+
5
9
  ## 8.4.0 (2023-02-15)
6
10
 
7
11
  ## 8.3.0 (2023-02-01)
package/README.md CHANGED
@@ -508,10 +508,6 @@ import { store as myCustomStore } from 'my-custom-store';
508
508
  dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
509
509
  ```
510
510
 
511
- _Type_
512
-
513
- - `(storeNameOrDescriptor: StoreDescriptor|string) => Object`
514
-
515
511
  _Parameters_
516
512
 
517
513
  - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
@@ -659,10 +655,6 @@ import { store as myCustomStore } from 'my-custom-store';
659
655
  select( myCustomStore ).getPrice( 'hammer' );
660
656
  ```
661
657
 
662
- _Type_
663
-
664
- - `(storeNameOrDescriptor: StoreDescriptor|string) => Object`
665
-
666
658
  _Parameters_
667
659
 
668
660
  - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported.
@@ -33,8 +33,9 @@ const renderQueue = (0, _priorityQueue.createQueue)();
33
33
 
34
34
  /**
35
35
  * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
36
- * @template State,Selectors
36
+ * @template State
37
37
  * @template {Record<string,import('../../types').ActionCreator>} Actions
38
+ * @template Selectors
38
39
  */
39
40
 
40
41
  /** @typedef {import('../../types').MapSelect} MapSelect */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscribe","createSubscriber","stores","listener","onStoreChange","onChange","add","unsubs","map","storeName","unsub","cancel","mapSelect","resubscribe","isAsync","selectValue","updateValue","selectFromStore","mapResult","getValue","listeningStores","current","__unstableMarkListeningStores","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAOA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;AACA;AACA;AACA;;AAEA,SAASC,KAAT,CAAgBC,QAAhB,EAA0BC,QAA1B,EAAqC;AACpC,QAAMC,MAAM,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,aAAZ,GAA4BH,QAAQ,CAACE,MAA5D;AACA,QAAME,YAAY,GAAG,EAArB;AACA,MAAIC,aAAJ;AACA,MAAIC,aAAJ;AACA,MAAIC,kBAAkB,GAAG,KAAzB;AACA,MAAIC,WAAJ;AACA,MAAIC,SAAJ;;AAEA,QAAMC,gBAAgB,GAAKC,MAAF,IAAgBC,QAAF,IAAgB;AACt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EzB,IAAAA,SAAF;AAAamB,IAAAA;AAAb,MAA0BO,KAAK,CAAEC,QAAF,EAAY,CAAC,CAAEF,IAAf,EAAqBX,OAArB,CAArC;AACA,QAAMc,MAAM,GAAG,mCAAsB5B,SAAtB,EAAiCmB,QAAjC,EAA2CA,QAA3C,CAAf;AACA,8BAAeS,MAAf;AACA,SAAOA,MAAP;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,CAAoBjB,SAApB,EAA+Ba,IAA/B,EAAsC;AACpD;AACA;AACA,QAAMK,gBAAgB,GAAG,OAAOlB,SAAP,KAAqB,UAA9C;AACA,QAAMmB,mBAAmB,GAAG,qBAAQD,gBAAR,CAA5B;;AAEA,MAAKA,gBAAgB,KAAKC,mBAAmB,CAACV,OAA9C,EAAwD;AACvD,UAAMW,QAAQ,GAAGD,mBAAmB,CAACV,OAApB,GAA8B,QAA9B,GAAyC,SAA1D;AACA,UAAMY,QAAQ,GAAGH,gBAAgB,GAAG,QAAH,GAAc,SAA/C;AACA,UAAM,IAAII,KAAJ,CACJ,4BAA4BF,QAAU,OAAOC,QAAU,iBADnD,CAAN;AAGA;AAED;AACA;AACA;;;AACA,SAAOH,gBAAgB,GACpBP,eAAe,CAAEX,SAAF,CADK,GAEpBY,gBAAgB,CAAE,KAAF,EAASZ,SAAT,EAAoBa,IAApB,CAFnB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,iBAAT,CAA4BvB,SAA5B,EAAuCa,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQZ,SAAR,EAAmBa,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Selectors\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscribe;\n\n\tconst createSubscriber = ( stores ) => ( listener ) => {\n\t\t// Invalidate the value right after subscription was created. React will\n\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t// in the interval between the `getValue` call during render and creating\n\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t// second `getValue` call will compute a fresh value.\n\t\tlastMapResultValid = false;\n\n\t\tconst onStoreChange = () => {\n\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\tlastMapResultValid = false;\n\t\t\tlistener();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( lastIsAsync ) {\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\tconst unsubs = stores.map( ( storeName ) => {\n\t\t\treturn registry.subscribe( onChange, storeName );\n\t\t} );\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\tfor ( const unsub of unsubs ) {\n\t\t\t\tunsub?.();\n\t\t\t}\n\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\trenderQueue.cancel( queueContext );\n\t\t};\n\t};\n\n\treturn ( mapSelect, resubscribe, isAsync ) => {\n\t\tconst selectValue = () => mapSelect( select, registry );\n\n\t\tfunction updateValue( selectFromStore ) {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst mapResult = selectFromStore();\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue( selectValue );\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\t// Either initialize the `subscribe` function, or create a new one if `mapSelect`\n\t\t// changed and has dependencies.\n\t\t// Usage without dependencies, `useSelect( ( s ) => { ... } )`, will subscribe\n\t\t// only once, at mount, and won't resubscibe even if `mapSelect` changes.\n\t\tif ( ! subscribe || ( resubscribe && mapSelect !== lastMapSelect ) ) {\n\t\t\t// Find out what stores the `mapSelect` callback is selecting from and\n\t\t\t// use that list to create subscriptions to specific stores.\n\t\t\tconst listeningStores = { current: null };\n\t\t\tupdateValue( () =>\n\t\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t\tselectValue,\n\t\t\t\t\tlisteningStores\n\t\t\t\t)\n\t\t\t);\n\t\t\tsubscribe = createSubscriber( listeningStores.current );\n\t\t} else {\n\t\t\tupdateValue( selectValue );\n\t\t}\n\n\t\tlastIsAsync = isAsync;\n\t\tlastMapSelect = mapSelect;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, !! deps, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\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\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\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\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscribe","createSubscriber","stores","listener","onStoreChange","onChange","add","unsubs","map","storeName","unsub","cancel","mapSelect","resubscribe","isAsync","selectValue","updateValue","selectFromStore","mapResult","getValue","listeningStores","current","__unstableMarkListeningStores","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAOA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;AACA;AACA;AACA;;AAEA,SAASC,KAAT,CAAgBC,QAAhB,EAA0BC,QAA1B,EAAqC;AACpC,QAAMC,MAAM,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,aAAZ,GAA4BH,QAAQ,CAACE,MAA5D;AACA,QAAME,YAAY,GAAG,EAArB;AACA,MAAIC,aAAJ;AACA,MAAIC,aAAJ;AACA,MAAIC,kBAAkB,GA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nB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,iBAAT,CAA4BvB,SAA5B,EAAuCa,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQZ,SAAR,EAAmBa,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscribe;\n\n\tconst createSubscriber = ( stores ) => ( listener ) => {\n\t\t// Invalidate the value right after subscription was created. React will\n\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t// in the interval between the `getValue` call during render and creating\n\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t// second `getValue` call will compute a fresh value.\n\t\tlastMapResultValid = false;\n\n\t\tconst onStoreChange = () => {\n\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\tlastMapResultValid = false;\n\t\t\tlistener();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( lastIsAsync ) {\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\tconst unsubs = stores.map( ( storeName ) => {\n\t\t\treturn registry.subscribe( onChange, storeName );\n\t\t} );\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\tfor ( const unsub of unsubs ) {\n\t\t\t\tunsub?.();\n\t\t\t}\n\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\trenderQueue.cancel( queueContext );\n\t\t};\n\t};\n\n\treturn ( mapSelect, resubscribe, isAsync ) => {\n\t\tconst selectValue = () => mapSelect( select, registry );\n\n\t\tfunction updateValue( selectFromStore ) {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst mapResult = selectFromStore();\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue( selectValue );\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\t// Either initialize the `subscribe` function, or create a new one if `mapSelect`\n\t\t// changed and has dependencies.\n\t\t// Usage without dependencies, `useSelect( ( s ) => { ... } )`, will subscribe\n\t\t// only once, at mount, and won't resubscibe even if `mapSelect` changes.\n\t\tif ( ! subscribe || ( resubscribe && mapSelect !== lastMapSelect ) ) {\n\t\t\t// Find out what stores the `mapSelect` callback is selecting from and\n\t\t\t// use that list to create subscriptions to specific stores.\n\t\t\tconst listeningStores = { current: null };\n\t\t\tupdateValue( () =>\n\t\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t\tselectValue,\n\t\t\t\t\tlisteningStores\n\t\t\t\t)\n\t\t\t);\n\t\t\tsubscribe = createSubscriber( listeningStores.current );\n\t\t} else {\n\t\t\tupdateValue( selectValue );\n\t\t}\n\n\t\tlastIsAsync = isAsync;\n\t\tlastMapSelect = mapSelect;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, !! deps, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\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\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\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\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
@@ -23,6 +23,8 @@ var _useDispatch = require("../use-dispatch");
23
23
  * Internal dependencies
24
24
  */
25
25
 
26
+ /** @typedef {import('@wordpress/element').WPComponent} WPComponent */
27
+
26
28
  /**
27
29
  * Higher-order component used to add dispatch props using registered action
28
30
  * creators.
@@ -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;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
+ {"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;;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;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/** @typedef {import('@wordpress/element').WPComponent} WPComponent */\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"]}
@@ -23,6 +23,8 @@ var _useSelect = _interopRequireDefault(require("../use-select"));
23
23
  * Internal dependencies
24
24
  */
25
25
 
26
+ /** @typedef {import('@wordpress/element').WPComponent} WPComponent */
27
+
26
28
  /**
27
29
  * Higher-order component used to inject state-derived props using registered
28
30
  * selectors.
@@ -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;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"]}
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;;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,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/** @typedef {import('@wordpress/element').WPComponent} WPComponent */\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/index.js CHANGED
@@ -54,7 +54,10 @@ Object.defineProperty(exports, "createRegistrySelector", {
54
54
  return _factory.createRegistrySelector;
55
55
  }
56
56
  });
57
- exports.use = exports.suspendSelect = exports.subscribe = exports.select = exports.resolveSelect = exports.registerStore = exports.registerGenericStore = exports.register = exports.plugins = exports.dispatch = void 0;
57
+ exports.dispatch = dispatch;
58
+ exports.resolveSelect = exports.registerStore = exports.registerGenericStore = exports.register = exports.plugins = void 0;
59
+ exports.select = select;
60
+ exports.use = exports.suspendSelect = exports.subscribe = void 0;
58
61
  Object.defineProperty(exports, "useDispatch", {
59
62
  enumerable: true,
60
63
  get: function () {
@@ -208,12 +211,13 @@ const combineReducers = _turboCombineReducers.default;
208
211
  * ```
209
212
  *
210
213
  * @return {Object} Object containing the store's selectors.
211
- *
212
- * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object}
213
214
  */
214
215
 
215
216
  exports.combineReducers = combineReducers;
216
- const select = _defaultRegistry.default.select;
217
+
218
+ function select(storeNameOrDescriptor) {
219
+ return _defaultRegistry.default.select(storeNameOrDescriptor);
220
+ }
217
221
  /**
218
222
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
219
223
  * so that you only need to supply additional arguments, and modified so that they return promises
@@ -234,7 +238,7 @@ const select = _defaultRegistry.default.select;
234
238
  * @return {Object} Object containing the store's promise-wrapped selectors.
235
239
  */
236
240
 
237
- exports.select = select;
241
+
238
242
  const resolveSelect = _defaultRegistry.default.resolveSelect;
239
243
  /**
240
244
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
@@ -269,12 +273,13 @@ const suspendSelect = _defaultRegistry.default.suspendSelect;
269
273
  * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
270
274
  * ```
271
275
  * @return {Object} Object containing the action creators.
272
- *
273
- * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object}
274
276
  */
275
277
 
276
278
  exports.suspendSelect = suspendSelect;
277
- const dispatch = _defaultRegistry.default.dispatch;
279
+
280
+ function dispatch(storeNameOrDescriptor) {
281
+ return _defaultRegistry.default.dispatch(storeNameOrDescriptor);
282
+ }
278
283
  /**
279
284
  * Given a listener function, the function will be called any time the state value
280
285
  * of one of the registered stores has changed. If you specify the optional
@@ -300,7 +305,7 @@ const dispatch = _defaultRegistry.default.dispatch;
300
305
  * ```
301
306
  */
302
307
 
303
- exports.dispatch = dispatch;
308
+
304
309
  const subscribe = _defaultRegistry.default.subscribe;
305
310
  /**
306
311
  * Registers a generic store instance.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/index.js"],"names":["combineReducers","turboCombineReducers","select","defaultRegistry","resolveSelect","suspendSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAqBA;AACA;AACA;AACA;AACA;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;AACO,MAAMA,eAAe,GAAGC,6BAAxB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,MAAM,GAAGC,yBAAgBD,MAA/B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,aAAa,GAAGD,yBAAgBC,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGF,yBAAgBE,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGH,yBAAgBG,QAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,SAAS,GAAGJ,yBAAgBI,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,oBAAoB,GAAGL,yBAAgBK,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGN,yBAAgBM,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,GAAG,GAAGP,yBAAgBO,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGR,yBAAgBQ,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport turboCombineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers = turboCombineReducers;\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return {Object} Object containing the store's selectors.\n *\n * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object}\n */\nexport const select = defaultRegistry.select;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they return promises\n * that resolve to their eventual values, after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = defaultRegistry.suspendSelect;\n\n/**\n * Given a store descriptor, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return {Object} Object containing the action creators.\n *\n * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object}\n */\nexport const dispatch = defaultRegistry.dispatch;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/index.js"],"names":["combineReducers","turboCombineReducers","select","storeNameOrDescriptor","defaultRegistry","resolveSelect","suspendSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAqBA;AACA;AACA;AACA;AACA;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;AACO,MAAMA,eAAe,GAAGC,6BAAxB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASC,MAAT,CAAiBC,qBAAjB,EAAyC;AAC/C,SAAOC,yBAAgBF,MAAhB,CAAwBC,qBAAxB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,aAAa,GAAGD,yBAAgBC,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGF,yBAAgBE,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASC,QAAT,CAAmBJ,qBAAnB,EAA2C;AACjD,SAAOC,yBAAgBG,QAAhB,CAA0BJ,qBAA1B,CAAP;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;;;AACO,MAAMK,SAAS,GAAGJ,yBAAgBI,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,oBAAoB,GAAGL,yBAAgBK,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGN,yBAAgBM,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,GAAG,GAAGP,yBAAgBO,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGR,yBAAgBQ,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport turboCombineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers = turboCombineReducers;\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return {Object} Object containing the store's selectors.\n */\nexport function select( storeNameOrDescriptor ) {\n\treturn defaultRegistry.select( storeNameOrDescriptor );\n}\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they return promises\n * that resolve to their eventual values, after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = defaultRegistry.suspendSelect;\n\n/**\n * Given a store descriptor, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return {Object} Object containing the action creators.\n */\nexport function dispatch( storeNameOrDescriptor ) {\n\treturn defaultRegistry.dispatch( storeNameOrDescriptor );\n}\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"]}
@@ -58,8 +58,9 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
58
58
 
59
59
  /**
60
60
  * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
61
- * @template State,Selectors
61
+ * @template State
62
62
  * @template {Record<string,import('../../types').ActionCreator>} Actions
63
+ * @template Selectors
63
64
  */
64
65
  const trimUndefinedValues = array => {
65
66
  const result = [...array];
@@ -143,8 +144,9 @@ function createResolversCache() {
143
144
  * } );
144
145
  * ```
145
146
  *
146
- * @template State,Selectors
147
+ * @template State
147
148
  * @template {Record<string,import('../../types').ActionCreator>} Actions
149
+ * @template Selectors
148
150
  * @param {string} key Unique namespace identifier.
149
151
  * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties
150
152
  * describing reducer, actions, selectors,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["trimUndefinedValues","array","result","i","length","undefined","splice","mapValues","obj","callback","Object","entries","reduce","acc","key","value","mapToObject","state","Map","fromEntries","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","options","privateActions","privateSelectors","privateRegistrationFunctions","registerPrivateActions","actions","assign","registerPrivateSelectors","selectors","storeDescriptor","name","instantiate","registry","reducer","thunkArgs","dispatch","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","mapActions","metadataActions","Proxy","target","prop","mapSelectors","metadataSelectors","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","suspendSelectors","mapSuspendSelectors","getSuspendSelectors","getState","subscribe","listener","lastState","hasChanged","controls","builtinControls","normalizedControls","control","isRegistryControl","middlewares","promise","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","serialize","replacer","initialState","enhancedReducer","metadataReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","getIsResolving","hasStartedResolution","hasFinishedResolution","hasResolutionFailed","isResolving","getCachedResolvers","getResolutionState","getResolutionError","storeSelectors","apply","reject","hasFinished","finalize","hasFailed","error","getResult","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAvBA;AACA;AACA;;AAKA;AACA;AACA;;AAIA;AACA;AACA;;AAUA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAAP,GAAgB,CAA9B,EAAiCD,CAAC,IAAI,CAAtC,EAAyCA,CAAC,EAA1C,EAA+C;AAC9C,QAAKD,MAAM,CAAEC,CAAF,CAAN,KAAgBE,SAArB,EAAiC;AAChCH,MAAAA,MAAM,CAACI,MAAP,CAAeH,CAAf,EAAkB,CAAlB;AACA;AACD;;AACD,SAAOD,MAAP;AACA,CARD;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMK,SAAS,GAAG,CAAEC,GAAF,EAAOC,QAAP,KACjBC,MAA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MA,WAbD,CAaE,OAAQkG,KAAR,EAAgB;AACjBzE,YAAAA,KAAK,CAACF,QAAN,CACCc,eAAe,CAAC2E,cAAhB,CACCjH,YADD,EAECC,IAFD,EAGCkG,KAHD,CADD;AAOA;AACD,SA3BS,CAAV;AA4BA;;AAEDQ,MAAAA,eAAe,CAAE,GAAG1G,IAAL,CAAf;AACA,aAAO4B,QAAQ,CAAE,GAAG5B,IAAL,CAAf;AACA,KA1DD;;AA2DAyG,IAAAA,gBAAgB,CAACzB,WAAjB,GAA+B,IAA/B;AACA,WAAOyB,gBAAP;AACA,GApED;;AAsEA,SAAO;AACNtE,IAAAA,SAAS,EAAEkE,eADL;AAENrF,IAAAA,SAAS,EAAEjC,SAAS,CAAEiC,SAAF,EAAawF,WAAb;AAFd,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,eAAf,CAAgCrF,KAAhC,EAAuCU,SAAvC,EAAkDpC,YAAlD,EAA0E;AACzE,QAAMuG,QAAQ,GAAGnE,SAAS,CAAEpC,YAAF,CAA1B;;AACA,MAAK,CAAEuG,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPtG,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMwB,MAAM,GAAG8E,QAAQ,CAACC,OAAT,CAAkB,GAAGvG,IAArB,CAAf;;AACA,MAAKwB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACF,QAAN,CAAgBC,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport { lock } from '../private-apis';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/**\n * @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../types').AnyConfig} C\n */\n/**\n * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Selectors\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.entries( obj ?? {} ).reduce(\n\t\t( acc, [ key, value ] ) => ( {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value, key ),\n\t\t} ),\n\t\t{}\n\t);\n\n// Convert Map objects to plain objects\nconst mapToObject = ( key, state ) => {\n\tif ( state instanceof Map ) {\n\t\treturn Object.fromEntries( state );\n\t}\n\n\treturn state;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @template State,Selectors\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\tconst privateActions = {};\n\tconst privateSelectors = {};\n\tconst privateRegistrationFunctions = {\n\t\tprivateActions,\n\t\tregisterPrivateActions: ( actions ) => {\n\t\t\tObject.assign( privateActions, actions );\n\t\t},\n\t\tprivateSelectors,\n\t\tregisterPrivateSelectors: ( selectors ) => {\n\t\t\tObject.assign( privateSelectors, selectors );\n\t\t},\n\t};\n\tconst storeDescriptor = {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\t// Expose the private registration functions on the store\n\t\t\t// so they can be copied to a sub registry in registry.js.\n\t\t\tlock( store, privateRegistrationFunctions );\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tlock(\n\t\t\t\tactions,\n\t\t\t\tnew Proxy( privateActions, {\n\t\t\t\t\tget: ( target, prop ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tmapActions( privateActions, store )[ prop ] ||\n\t\t\t\t\t\t\tactions[ prop ]\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\t( state, ...args ) =>\n\t\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tlock(\n\t\t\t\tselectors,\n\t\t\t\tnew Proxy( privateSelectors, {\n\t\t\t\t\tget: ( target, prop ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tmapSelectors(\n\t\t\t\t\t\t\t\tmapValues(\n\t\t\t\t\t\t\t\t\tprivateSelectors,\n\t\t\t\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\t\t\t\t( state, ...args ) =>\n\t\t\t\t\t\t\t\t\t\t\tselector( state.root, ...args )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tstore\n\t\t\t\t\t\t\t)[ prop ] || selectors[ prop ]\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\t\t\tconst suspendSelectors = mapSuspendSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\t\t\tconst getSuspendSelectors = () => suspendSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetSuspendSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Expose the private registration functions on the store\n\t// descriptor. That's a natural choice since that's where the\n\t// public actions and selectors are stored .\n\tlock( storeDescriptor, privateRegistrationFunctions );\n\n\treturn storeDescriptor;\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t\tserialize: {\n\t\t\t\t\treplacer: mapToObject,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tcompose( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction =\n\t\t( action ) =>\n\t\t( ...args ) => {\n\t\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\tconst {\n\t\tgetIsResolving,\n\t\thasStartedResolution,\n\t\thasFinishedResolution,\n\t\thasResolutionFailed,\n\t\tisResolving,\n\t\tgetCachedResolvers,\n\t\tgetResolutionState,\n\t\tgetResolutionError,\n\t\t...storeSelectors\n\t} = selectors;\n\n\treturn mapValues( storeSelectors, ( selector, selectorName ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args ) => selector.apply( null, args );\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed = selectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = selectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Maps selectors to functions that throw a suspense promise if not yet resolved.\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their suspense functions.\n */\nfunction mapSuspendSelectors( selectors, store ) {\n\treturn mapValues( selectors, ( selector, selectorName ) => {\n\t\t// Selector without a resolver doesn't have any extra suspense behavior.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn selector;\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\tconst result = selector.apply( null, args );\n\n\t\t\tif ( selectors.hasFinishedResolution( selectorName, args ) ) {\n\t\t\t\tif ( selectors.hasResolutionFailed( selectorName, args ) ) {\n\t\t\t\t\tthrow selectors.getResolutionError( selectorName, args );\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tthrow new Promise( ( resolve ) => {\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\t\tfulfill: resolver, // Add the fulfill method.\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.finishResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch ( error ) {\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.failResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs,\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = resolvers[ selectorName ];\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["trimUndefinedValues","array","result","i","length","undefined","splice","mapValues","obj","callback","Object","entries","reduce","acc","key","value","mapToObject","state","Map","fromEntries","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","options","privateActions","privateSelectors","privateRegistrationFunctions","registerPrivateActions","actions","assign","registerPrivateSelectors","selectors","storeDescriptor","name","instantiate","registry","reducer","thunkArgs","dispatch","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","mapActions","metadataActions","Proxy","target","prop","mapSelectors","metadataSelectors","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","suspendSelectors","mapSuspendSelectors","getSuspendSelectors","getState","subscribe","listener","lastState","hasChanged","controls","builtinControls","normalizedControls","control","isRegistryControl","middlewares","promise","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","serialize","replacer","initialState","enhancedReducer","metadataReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","getIsResolving","hasStartedResolution","hasFinishedResolution","hasResolutionFailed","isResolving","getCachedResolvers","getResolutionState","getResolutionError","storeSelectors","apply","reject","hasFinished","finalize","hasFailed","error","getResult","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAvBA;AACA;AACA;;AAKA;AACA;AACA;;AAIA;AACA;AACA;;AAUA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAAP,GAAgB,CAA9B,EAAiCD,CAAC,IAAI,CAAtC,EAAyCA,CAAC,EAA1C,EAA+C;AAC9C,QAAKD,MAAM,CAAEC,CAAF,CAAN,KAAgBE,SAArB,EAAiC;AAChCH,MAAAA,MAAM,CAACI,MAAP,CAAeH,CAAf,EAAkB,CAAlB;AACA;AACD;;AACD,SAAOD,MAAP;AACA,CARD;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMK,SAAS,GAAG,CAAEC,GAAF,EAAOC,QAAP,KACjBC,MAAM,CAACC,OAAP,CAAgBH,GAAhB,aAAgBA,GAAhB,cAAgBA,GAAhB,GAAuB,EAAvB,EAA4BI,MAA5B,CACC,CAAEC,GAAF;AAAA,MAAO,CAAEC,GAAF,EAAOC,KAAP,CAAP;AAAA,S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BS,CAAV;AA4BA;;AAEDQ,MAAAA,eAAe,CAAE,GAAG1G,IAAL,CAAf;AACA,aAAO4B,QAAQ,CAAE,GAAG5B,IAAL,CAAf;AACA,KA1DD;;AA2DAyG,IAAAA,gBAAgB,CAACzB,WAAjB,GAA+B,IAA/B;AACA,WAAOyB,gBAAP;AACA,GApED;;AAsEA,SAAO;AACNtE,IAAAA,SAAS,EAAEkE,eADL;AAENrF,IAAAA,SAAS,EAAEjC,SAAS,CAAEiC,SAAF,EAAawF,WAAb;AAFd,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,eAAf,CAAgCrF,KAAhC,EAAuCU,SAAvC,EAAkDpC,YAAlD,EAA0E;AACzE,QAAMuG,QAAQ,GAAGnE,SAAS,CAAEpC,YAAF,CAA1B;;AACA,MAAK,CAAEuG,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPtG,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMwB,MAAM,GAAG8E,QAAQ,CAACC,OAAT,CAAkB,GAAGvG,IAArB,CAAf;;AACA,MAAKwB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACF,QAAN,CAAgBC,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport { lock } from '../private-apis';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/**\n * @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../types').AnyConfig} C\n */\n/**\n * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.entries( obj ?? {} ).reduce(\n\t\t( acc, [ key, value ] ) => ( {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value, key ),\n\t\t} ),\n\t\t{}\n\t);\n\n// Convert Map objects to plain objects\nconst mapToObject = ( key, state ) => {\n\tif ( state instanceof Map ) {\n\t\treturn Object.fromEntries( state );\n\t}\n\n\treturn state;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\tconst privateActions = {};\n\tconst privateSelectors = {};\n\tconst privateRegistrationFunctions = {\n\t\tprivateActions,\n\t\tregisterPrivateActions: ( actions ) => {\n\t\t\tObject.assign( privateActions, actions );\n\t\t},\n\t\tprivateSelectors,\n\t\tregisterPrivateSelectors: ( selectors ) => {\n\t\t\tObject.assign( privateSelectors, selectors );\n\t\t},\n\t};\n\tconst storeDescriptor = {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\t// Expose the private registration functions on the store\n\t\t\t// so they can be copied to a sub registry in registry.js.\n\t\t\tlock( store, privateRegistrationFunctions );\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tlock(\n\t\t\t\tactions,\n\t\t\t\tnew Proxy( privateActions, {\n\t\t\t\t\tget: ( target, prop ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tmapActions( privateActions, store )[ prop ] ||\n\t\t\t\t\t\t\tactions[ prop ]\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\t( state, ...args ) =>\n\t\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tlock(\n\t\t\t\tselectors,\n\t\t\t\tnew Proxy( privateSelectors, {\n\t\t\t\t\tget: ( target, prop ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tmapSelectors(\n\t\t\t\t\t\t\t\tmapValues(\n\t\t\t\t\t\t\t\t\tprivateSelectors,\n\t\t\t\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\t\t\t\t( state, ...args ) =>\n\t\t\t\t\t\t\t\t\t\t\tselector( state.root, ...args )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tstore\n\t\t\t\t\t\t\t)[ prop ] || selectors[ prop ]\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\t\t\tconst suspendSelectors = mapSuspendSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\t\t\tconst getSuspendSelectors = () => suspendSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetSuspendSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Expose the private registration functions on the store\n\t// descriptor. That's a natural choice since that's where the\n\t// public actions and selectors are stored .\n\tlock( storeDescriptor, privateRegistrationFunctions );\n\n\treturn storeDescriptor;\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t\tserialize: {\n\t\t\t\t\treplacer: mapToObject,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tcompose( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction =\n\t\t( action ) =>\n\t\t( ...args ) => {\n\t\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\tconst {\n\t\tgetIsResolving,\n\t\thasStartedResolution,\n\t\thasFinishedResolution,\n\t\thasResolutionFailed,\n\t\tisResolving,\n\t\tgetCachedResolvers,\n\t\tgetResolutionState,\n\t\tgetResolutionError,\n\t\t...storeSelectors\n\t} = selectors;\n\n\treturn mapValues( storeSelectors, ( selector, selectorName ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args ) => selector.apply( null, args );\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed = selectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = selectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Maps selectors to functions that throw a suspense promise if not yet resolved.\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their suspense functions.\n */\nfunction mapSuspendSelectors( selectors, store ) {\n\treturn mapValues( selectors, ( selector, selectorName ) => {\n\t\t// Selector without a resolver doesn't have any extra suspense behavior.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn selector;\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\tconst result = selector.apply( null, args );\n\n\t\t\tif ( selectors.hasFinishedResolution( selectorName, args ) ) {\n\t\t\t\tif ( selectors.hasResolutionFailed( selectorName, args ) ) {\n\t\t\t\t\tthrow selectors.getResolutionError( selectorName, args );\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tthrow new Promise( ( resolve ) => {\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\t\tfulfill: resolver, // Add the fulfill method.\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.finishResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch ( error ) {\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.failResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs,\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = resolvers[ selectorName ];\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
@@ -18,8 +18,9 @@ const renderQueue = createQueue();
18
18
 
19
19
  /**
20
20
  * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
21
- * @template State,Selectors
21
+ * @template State
22
22
  * @template {Record<string,import('../../types').ActionCreator>} Actions
23
+ * @template Selectors
23
24
  */
24
25
 
25
26
  /** @typedef {import('../../types').MapSelect} MapSelect */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscribe","createSubscriber","stores","listener","onStoreChange","onChange","add","unsubs","map","storeName","unsub","cancel","mapSelect","resubscribe","isAsync","selectValue","updateValue","selectFromStore","mapResult","getValue","listeningStores","current","__unstableMarkListeningStores","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":"AAAA;AACA;AACA;AACA,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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,SAAT,CAAoBjB,SAApB,EAA+Ba,IAA/B,EAAsC;AACpD;AACA;AACA,QAAMK,gBAAgB,GAAG,OAAOlB,SAAP,KAAqB,UAA9C;AACA,QAAMmB,mBAAmB,GAAGlD,MAAM,CAAEiD,gBAAF,CAAlC;;AAEA,MAAKA,gBAAgB,KAAKC,mBAAmB,CAACV,OAA9C,EAAwD;AACvD,UAAMW,QAAQ,GAAGD,mBAAmB,CAACV,OAApB,GAA8B,QAA9B,GAAyC,SAA1D;AACA,UAAMY,QAAQ,GAAGH,gBAAgB,GAAG,QAAH,GAAc,SAA/C;AACA,UAAM,IAAII,KAAJ,CACJ,4BAA4BF,QAAU,OAAOC,QAAU,iBADnD,CAAN;AAGA;AAED;AACA;AACA;;;AACA,SAAOH,gBAAgB,GACpBP,eAAe,CAAEX,SAAF,CADK,GAEpBY,gBAAgB,CAAE,KAAF,EAASZ,SAAT,EAAoBa,IAApB,CAFnB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASU,iBAAT,CAA4BvB,SAA5B,EAAuCa,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQZ,SAAR,EAAmBa,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Selectors\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscribe;\n\n\tconst createSubscriber = ( stores ) => ( listener ) => {\n\t\t// Invalidate the value right after subscription was created. React will\n\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t// in the interval between the `getValue` call during render and creating\n\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t// second `getValue` call will compute a fresh value.\n\t\tlastMapResultValid = false;\n\n\t\tconst onStoreChange = () => {\n\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\tlastMapResultValid = false;\n\t\t\tlistener();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( lastIsAsync ) {\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\tconst unsubs = stores.map( ( storeName ) => {\n\t\t\treturn registry.subscribe( onChange, storeName );\n\t\t} );\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\tfor ( const unsub of unsubs ) {\n\t\t\t\tunsub?.();\n\t\t\t}\n\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\trenderQueue.cancel( queueContext );\n\t\t};\n\t};\n\n\treturn ( mapSelect, resubscribe, isAsync ) => {\n\t\tconst selectValue = () => mapSelect( select, registry );\n\n\t\tfunction updateValue( selectFromStore ) {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst mapResult = selectFromStore();\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue( selectValue );\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\t// Either initialize the `subscribe` function, or create a new one if `mapSelect`\n\t\t// changed and has dependencies.\n\t\t// Usage without dependencies, `useSelect( ( s ) => { ... } )`, will subscribe\n\t\t// only once, at mount, and won't resubscibe even if `mapSelect` changes.\n\t\tif ( ! subscribe || ( resubscribe && mapSelect !== lastMapSelect ) ) {\n\t\t\t// Find out what stores the `mapSelect` callback is selecting from and\n\t\t\t// use that list to create subscriptions to specific stores.\n\t\t\tconst listeningStores = { current: null };\n\t\t\tupdateValue( () =>\n\t\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t\tselectValue,\n\t\t\t\t\tlisteningStores\n\t\t\t\t)\n\t\t\t);\n\t\t\tsubscribe = createSubscriber( listeningStores.current );\n\t\t} else {\n\t\t\tupdateValue( selectValue );\n\t\t}\n\n\t\tlastIsAsync = isAsync;\n\t\tlastMapSelect = mapSelect;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, !! deps, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\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\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\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\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscribe","createSubscriber","stores","listener","onStoreChange","onChange","add","unsubs","map","storeName","unsub","cancel","mapSelect","resubscribe","isAsync","selectValue","updateValue","selectFromStore","mapResult","getValue","listeningStores","current","__unstableMarkListeningStores","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,2BAA5B;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,OAHD,EAICC,oBAJD,EAKCC,aALD,QAMO,oBANP;AAOA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AACA,OAAOC,YAAP,MAAyB,uCAAzB;AAEA,MAAMC,WAAW,GAAGT,WAAW,EAA/B;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;AACA;AACA;AACA;;AAEA,SAASU,KAAT,CAAgBC,QAAhB,EAA0BC,QAA1B,EAAqC;AACpC,QAAMC,MAAM,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,aAAZ,GAA4BH,QAAQ,CAACE,MAA5D;AACA,QAAME,YAAY,GAAG,EAArB;AACA,MAAIC,aAAJ;AACA,MAAIC,aAAJ;AACA,MAAIC,kBAAkB,GAAG,KAAzB;AACA,MAAIC,WAAJ;AACA,MAAIC,SAAJ;;AAEA,QAAMC,gBAAgB,GAAKC,MAAF,IAAgBC,QAAF,IAAgB;AACtD;AACA;AACA;AACA;AACA;AACAL,IAAAA,kBAAkB,GAAG,KAArB;;AAEA,UAAMM,aAAa,GAAG,MAAM;AAC3B;AACAN,MAAAA,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,CAAC,CAAEF,IAAf,EAAqBX,OAArB,CAArC;AACA,QAAMc,MAAM,GAAG5C,oBAAoB,CAAEgB,SAAF,EAAamB,QAAb,EAAuBA,QAAvB,CAAnC;AACAlC,EAAAA,aAAa,CAAE2C,MAAF,CAAb;AACA,SAAOA,MAAP;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,SAAT,CAAoBjB,SAApB,EAA+Ba,IAA/B,EAAsC;AACpD;AACA;AACA,QAAMK,gBAAgB,GAAG,OAAOlB,SAAP,KAAqB,UAA9C;AACA,QAAMmB,mBAAmB,GAAGlD,MAAM,CAAEiD,gBAAF,CAAlC;;AAEA,MAAKA,gBAAgB,KAAKC,mBAAmB,CAACV,OAA9C,EAAwD;AACvD,UAAMW,QAAQ,GAAGD,mBAAmB,CAACV,OAApB,GAA8B,QAA9B,GAAyC,SAA1D;AACA,UAAMY,QAAQ,GAAGH,gBAAgB,GAAG,QAAH,GAAc,SAA/C;AACA,UAAM,IAAII,KAAJ,CACJ,4BAA4BF,QAAU,OAAOC,QAAU,iBADnD,CAAN;AAGA;AAED;AACA;AACA;;;AACA,SAAOH,gBAAgB,GACpBP,eAAe,CAAEX,SAAF,CADK,GAEpBY,gBAAgB,CAAE,KAAF,EAASZ,SAAT,EAAoBa,IAApB,CAFnB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASU,iBAAT,CAA4BvB,SAA5B,EAAuCa,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQZ,SAAR,EAAmBa,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscribe;\n\n\tconst createSubscriber = ( stores ) => ( listener ) => {\n\t\t// Invalidate the value right after subscription was created. React will\n\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t// in the interval between the `getValue` call during render and creating\n\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t// second `getValue` call will compute a fresh value.\n\t\tlastMapResultValid = false;\n\n\t\tconst onStoreChange = () => {\n\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\tlastMapResultValid = false;\n\t\t\tlistener();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( lastIsAsync ) {\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\tconst unsubs = stores.map( ( storeName ) => {\n\t\t\treturn registry.subscribe( onChange, storeName );\n\t\t} );\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\tfor ( const unsub of unsubs ) {\n\t\t\t\tunsub?.();\n\t\t\t}\n\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\trenderQueue.cancel( queueContext );\n\t\t};\n\t};\n\n\treturn ( mapSelect, resubscribe, isAsync ) => {\n\t\tconst selectValue = () => mapSelect( select, registry );\n\n\t\tfunction updateValue( selectFromStore ) {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst mapResult = selectFromStore();\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue( selectValue );\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\t// Either initialize the `subscribe` function, or create a new one if `mapSelect`\n\t\t// changed and has dependencies.\n\t\t// Usage without dependencies, `useSelect( ( s ) => { ... } )`, will subscribe\n\t\t// only once, at mount, and won't resubscibe even if `mapSelect` changes.\n\t\tif ( ! subscribe || ( resubscribe && mapSelect !== lastMapSelect ) ) {\n\t\t\t// Find out what stores the `mapSelect` callback is selecting from and\n\t\t\t// use that list to create subscriptions to specific stores.\n\t\t\tconst listeningStores = { current: null };\n\t\t\tupdateValue( () =>\n\t\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t\tselectValue,\n\t\t\t\t\tlisteningStores\n\t\t\t\t)\n\t\t\t);\n\t\t\tsubscribe = createSubscriber( listeningStores.current );\n\t\t} else {\n\t\t\tupdateValue( selectValue );\n\t\t}\n\n\t\tlastIsAsync = isAsync;\n\t\tlastMapSelect = mapSelect;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, !! deps, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\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\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\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\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
@@ -10,6 +10,8 @@ import { createHigherOrderComponent } from '@wordpress/compose';
10
10
  */
11
11
 
12
12
  import { useDispatchWithMap } from '../use-dispatch';
13
+ /** @typedef {import('@wordpress/element').WPComponent} WPComponent */
14
+
13
15
  /**
14
16
  * Higher-order component used to add dispatch props using registered action
15
17
  * creators.