@wordpress/data 7.6.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 8.0.0 (2022-12-14)
6
+
7
+ ### Breaking Changes
8
+
9
+ - Updated dependencies to require React 18 ([45235](https://github.com/WordPress/gutenberg/pull/45235))
10
+
11
+ ### Enhancements
12
+
13
+ - The `registry.subscribe` function can now subscribe to updates only from one specific store, with a new optional parameter.
14
+
5
15
  ## 7.6.0 (2022-11-16)
6
16
 
7
17
  ## 7.5.0 (2022-11-02)
package/README.md CHANGED
@@ -658,8 +658,11 @@ _Returns_
658
658
  ### subscribe
659
659
 
660
660
  Given a listener function, the function will be called any time the state value
661
- of one of the registered stores has changed. This function returns a `unsubscribe`
662
- function used to stop the subscription.
661
+ of one of the registered stores has changed. If you specify the optional
662
+ `storeNameOrDescriptor` parameter, the listener function will be called only
663
+ on updates on that one specific registered store.
664
+
665
+ This function returns an `unsubscribe` function used to stop the subscription.
663
666
 
664
667
  _Usage_
665
668
 
@@ -678,6 +681,7 @@ unsubscribe();
678
681
  _Parameters_
679
682
 
680
683
  - _listener_ `Function`: Callback function.
684
+ - _storeNameOrDescriptor_ `string|StoreDescriptor?`: Optional store name.
681
685
 
682
686
  ### suspendSelect
683
687
 
@@ -239,7 +239,7 @@ function useSelect(mapSelect, deps) {
239
239
 
240
240
 
241
241
  onStoreChange();
242
- const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
242
+ const unsubscribers = listeningStores.current.map(storeName => registry.subscribe(onChange, storeName));
243
243
  isMounted.current = true;
244
244
  return () => {
245
245
  // The return value of the subscribe function could be undefined if the store is a custom generic store.
@@ -355,7 +355,7 @@ function useSuspenseSelect(mapSelect, deps) {
355
355
 
356
356
 
357
357
  onStoreChange();
358
- const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
358
+ const unsubscribers = listeningStores.current.map(storeName => registry.subscribe(onChange, storeName));
359
359
  isMounted.current = true;
360
360
  return () => {
361
361
  // The return value of the subscribe function could be undefined if the store is a custom generic store.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","selectorRan","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe","cancel","useSuspenseSelect","suspendSelect","mapOutputError"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AAOA;;AACA;;AAKA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAA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AOE,OAAQZ,KAAR,EAAgB;AACjBd,QAAAA,oBAAoB,CAACS,OAArB,GAA+BK,KAA/B;AACA;;AAEDQ,MAAAA,WAAW;AACX,KAbD;;AAeA,UAAMK,QAAQ,GAAG,MAAM;AACtB,UAAK,CAAEH,SAAS,CAACf,OAAjB,EAA2B;AAC1B;AACA;;AAED,UAAKX,aAAa,CAACW,OAAnB,EAA6B;AAC5BtB,QAAAA,WAAW,CAACyC,GAAZ,CAAiBR,YAAjB,EAA+BK,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAVD,CAhBgC,CA4BhC;AACA;;;AACAA,IAAAA,aAAa;AAEb,UAAMI,aAAa,GAAG5B,eAAe,CAACQ,OAAhB,CAAwBqB,GAAxB,CAA+BC,SAAF,IAClDrC,QAAQ,CAACsC,wBAAT,CAAmCD,SAAnC,EAA8CJ,QAA9C,CADqB,CAAtB;AAIAH,IAAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA/C,MAAAA,WAAW,CAACgD,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD;AAMA,GA5CD,EA4CG,CAAEf,QAAF,EAAYQ,UAAZ,EAAwBI,eAAxB,CA5CH;;AA8CA,MAAKgC,cAAL,EAAsB;AACrB,UAAMA,cAAN;AACA;;AAED,SAAO/B,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,Selectors\n */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template T\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tlet selectorRan = false;\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t\tselectorRan = true;\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tif ( selectorRan ) {\n\t\t\tlatestMapOutput.current = mapOutput;\n\t\t}\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\tuseDebugValue( mapOutput );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\tconst _mapSelect = useCallback( mapSelect, deps );\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the `mapSelect` function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.suspendSelect, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput = latestMapOutput.current;\n\tlet mapOutputError = latestMapOutputError.current;\n\n\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\n\tlet selectorRan = false;\n\tif ( hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode ) {\n\t\ttry {\n\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\tselectorRan = true;\n\t\t} catch ( error ) {\n\t\t\tmapOutputError = error;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tif ( selectorRan ) {\n\t\t\tlatestMapOutput.current = mapOutput;\n\t\t}\n\t\tlatestMapOutputError.current = mapOutputError;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t}, [ registry, wrapSelect, depsChangedFlag ] );\n\n\tif ( mapOutputError ) {\n\t\tthrow mapOutputError;\n\t}\n\n\treturn mapOutput;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","selectorRan","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","subscribe","forEach","unsubscribe","cancel","useSuspenseSelect","suspendSelect","mapOutputError"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AAOA;;AACA;;AAKA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAAMC,kBAAkB,GAAG,eAAe,OAAOF,SAAjD,CADoD,CAGpD;AACA;AACA;;AACA,MAAK,CAAEE,kBAAP,EAA4B;AAC3BD,IAAAA,IAAI,GAAG,EAAP;AACA,GARmD,CAUpD;AACA;AACA;AACA;AACA;;;AACA,QAAME,cAAc,GAAG,0BACtBD,kBAAkB,GA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AAKX,aAAa,CAACW,OAAnB,EAA6B;AAC5BtB,QAAAA,WAAW,CAACyC,GAAZ,CAAiBR,YAAjB,EAA+BK,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAVD,CAhBgC,CA4BhC;AACA;;;AACAA,IAAAA,aAAa;AAEb,UAAMI,aAAa,GAAG5B,eAAe,CAACQ,OAAhB,CAAwBqB,GAAxB,CAA+BC,SAAF,IAClDrC,QAAQ,CAACsC,SAAT,CAAoBL,QAApB,EAA8BI,SAA9B,CADqB,CAAtB;AAIAP,IAAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA/C,MAAAA,WAAW,CAACgD,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD;AAMA,GA5CD,EA4CG,CAAEf,QAAF,EAAYQ,UAAZ,EAAwBI,eAAxB,CA5CH;;AA8CA,MAAKgC,cAAL,EAAsB;AACrB,UAAMA,cAAN;AACA;;AAED,SAAO/B,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,Selectors\n */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template T\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tlet selectorRan = false;\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t\tselectorRan = true;\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tif ( selectorRan ) {\n\t\t\tlatestMapOutput.current = mapOutput;\n\t\t}\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.subscribe( onChange, storeName )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\tuseDebugValue( mapOutput );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\tconst _mapSelect = useCallback( mapSelect, deps );\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the `mapSelect` function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.suspendSelect, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput = latestMapOutput.current;\n\tlet mapOutputError = latestMapOutputError.current;\n\n\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\n\tlet selectorRan = false;\n\tif ( hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode ) {\n\t\ttry {\n\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\tselectorRan = true;\n\t\t} catch ( error ) {\n\t\t\tmapOutputError = error;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tif ( selectorRan ) {\n\t\t\tlatestMapOutput.current = mapOutput;\n\t\t}\n\t\tlatestMapOutputError.current = mapOutputError;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.subscribe( onChange, storeName )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t}, [ registry, wrapSelect, depsChangedFlag ] );\n\n\tif ( mapOutputError ) {\n\t\tthrow mapOutputError;\n\t}\n\n\treturn mapOutput;\n}\n"]}
package/build/index.js CHANGED
@@ -273,10 +273,14 @@ exports.suspendSelect = suspendSelect;
273
273
  const dispatch = _defaultRegistry.default.dispatch;
274
274
  /**
275
275
  * Given a listener function, the function will be called any time the state value
276
- * of one of the registered stores has changed. This function returns a `unsubscribe`
277
- * function used to stop the subscription.
276
+ * of one of the registered stores has changed. If you specify the optional
277
+ * `storeNameOrDescriptor` parameter, the listener function will be called only
278
+ * on updates on that one specific registered store.
278
279
  *
279
- * @param {Function} listener Callback function.
280
+ * This function returns an `unsubscribe` function used to stop the subscription.
281
+ *
282
+ * @param {Function} listener Callback function.
283
+ * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.
280
284
  *
281
285
  * @example
282
286
  * ```js
@@ -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;;;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;;;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;;;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 */\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 */\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. This function returns a `unsubscribe`\n * function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\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","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,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;;;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 */\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 */\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"]}
@@ -70,6 +70,15 @@ const trimUndefinedValues = array => {
70
70
  }
71
71
 
72
72
  return result;
73
+ }; // Convert Map objects to plain objects
74
+
75
+
76
+ const mapToObject = (key, state) => {
77
+ if (state instanceof Map) {
78
+ return Object.fromEntries(state);
79
+ }
80
+
81
+ return state;
73
82
  };
74
83
  /**
75
84
  * Create a cache to track whether resolvers started running or not.
@@ -258,7 +267,10 @@ function instantiateReduxStore(key, options, registry, thunkArgs) {
258
267
  if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
259
268
  enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({
260
269
  name: key,
261
- instanceId: key
270
+ instanceId: key,
271
+ serialize: {
272
+ replacer: mapToObject
273
+ }
262
274
  }));
263
275
  }
264
276
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["trimUndefinedValues","array","result","i","length","undefined","splice","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","key","options","name","instantiate","registry","reducer","thunkArgs","dispatch","Object","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","metadataActions","selectors","mapSelectors","metadataSelectors","state","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","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;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAvBA;AACA;AACA;;AAMA;AACA;AACA;;AAIA;AACA;AACA;;AASA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAM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,IAA/B;AACA,WAAOyB,gBAAP;AACA,GApED;;AAsEA,SAAO;AACNpE,IAAAA,SAAS,EAAEgE,eADL;AAEN5D,IAAAA,SAAS,EAAE,uBAAWA,SAAX,EAAsB+D,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,eAAf,CAAgCnF,KAAhC,EAAuCU,SAAvC,EAAkD9B,YAAlD,EAA0E;AACzE,QAAM+F,QAAQ,GAAG,iBAAKjE,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAE+F,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAP9F,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMkB,MAAM,GAAG4E,QAAQ,CAACC,OAAT,CAAkB,GAAG/F,IAArB,CAAf;;AACA,MAAKkB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACJ,QAAN,CAAgBG,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { get, mapValues } from 'lodash';\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 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 C\n */\n/**\n * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,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 * 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,Actions,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\treturn {\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\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\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\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\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} )\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 = get( 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","mapToObject","key","state","Map","Object","fromEntries","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","options","name","instantiate","registry","reducer","thunkArgs","dispatch","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","metadataActions","selectors","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;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAvBA;AACA;AACA;;AAMA;AACA;AACA;;AAIA;AACA;AACA;;AASA;;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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CAAE,GAAGpB,IAAL,CAAf;AACA,KA1DD;;AA2DAgG,IAAAA,gBAAgB,CAACzB,WAAjB,GAA+B,IAA/B;AACA,WAAOyB,gBAAP;AACA,GApED;;AAsEA,SAAO;AACNrE,IAAAA,SAAS,EAAEiE,eADL;AAEN7D,IAAAA,SAAS,EAAE,uBAAWA,SAAX,EAAsBgE,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,eAAf,CAAgCpF,KAAhC,EAAuCU,SAAvC,EAAkD5B,YAAlD,EAA0E;AACzE,QAAM8F,QAAQ,GAAG,iBAAKlE,SAAL,EAAgB,CAAE5B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAE8F,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAP7F,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMgB,MAAM,GAAG6E,QAAQ,CAACC,OAAT,CAAkB,GAAG9F,IAArB,CAAf;;AACA,MAAKgB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACH,QAAN,CAAgBE,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { get, mapValues } from 'lodash';\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 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 C\n */\n/**\n * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State,Actions,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// 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,Actions,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\treturn {\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\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\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\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\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 = get( 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"]}
package/build/registry.js CHANGED
@@ -56,8 +56,8 @@ var _emitter = require("./utils/emitter");
56
56
  *
57
57
  * @property {Function} registerStore registers store.
58
58
  */
59
- function isObject(object) {
60
- return object !== null && typeof object === 'object';
59
+ function getStoreName(storeNameOrDescriptor) {
60
+ return typeof storeNameOrDescriptor === 'string' ? storeNameOrDescriptor : storeNameOrDescriptor.name;
61
61
  }
62
62
  /**
63
63
  * Creates a new store registry, given an optional object of initial store
@@ -84,16 +84,39 @@ function createRegistry() {
84
84
  emitter.emit();
85
85
  }
86
86
  /**
87
- * Subscribe to changes to any data.
87
+ * Subscribe to changes to any data, either in all stores in registry, or
88
+ * in one specific store.
88
89
  *
89
- * @param {Function} listener Listener function.
90
+ * @param {Function} listener Listener function.
91
+ * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.
90
92
  *
91
93
  * @return {Function} Unsubscribe function.
92
94
  */
93
95
 
94
96
 
95
- const subscribe = listener => {
96
- return emitter.subscribe(listener);
97
+ const subscribe = (listener, storeNameOrDescriptor) => {
98
+ // subscribe to all stores
99
+ if (!storeNameOrDescriptor) {
100
+ return emitter.subscribe(listener);
101
+ } // subscribe to one store
102
+
103
+
104
+ const storeName = getStoreName(storeNameOrDescriptor);
105
+ const store = stores[storeName];
106
+
107
+ if (store) {
108
+ return store.subscribe(listener);
109
+ } // Trying to access a store that hasn't been registered,
110
+ // this is a pattern rarely used but seen in some places.
111
+ // We fallback to global `subscribe` here for backward-compatibility for now.
112
+ // See https://github.com/WordPress/gutenberg/pull/27466 for more info.
113
+
114
+
115
+ if (!parent) {
116
+ return emitter.subscribe(listener);
117
+ }
118
+
119
+ return parent.subscribe(listener, storeNameOrDescriptor);
97
120
  };
98
121
  /**
99
122
  * Calls a selector given the current state and extra arguments.
@@ -106,7 +129,7 @@ function createRegistry() {
106
129
 
107
130
 
108
131
  function select(storeNameOrDescriptor) {
109
- const storeName = isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
132
+ const storeName = getStoreName(storeNameOrDescriptor);
110
133
  listeningStores.add(storeName);
111
134
  const store = stores[storeName];
112
135
 
@@ -140,7 +163,7 @@ function createRegistry() {
140
163
 
141
164
 
142
165
  function resolveSelect(storeNameOrDescriptor) {
143
- const storeName = isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
166
+ const storeName = getStoreName(storeNameOrDescriptor);
144
167
  listeningStores.add(storeName);
145
168
  const store = stores[storeName];
146
169
 
@@ -164,7 +187,7 @@ function createRegistry() {
164
187
 
165
188
 
166
189
  function suspendSelect(storeNameOrDescriptor) {
167
- const storeName = isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
190
+ const storeName = getStoreName(storeNameOrDescriptor);
168
191
  listeningStores.add(storeName);
169
192
  const store = stores[storeName];
170
193
 
@@ -185,7 +208,7 @@ function createRegistry() {
185
208
 
186
209
 
187
210
  function dispatch(storeNameOrDescriptor) {
188
- const storeName = isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
211
+ const storeName = getStoreName(storeNameOrDescriptor);
189
212
  const store = stores[storeName];
190
213
 
191
214
  if (store) {
@@ -292,33 +315,6 @@ function createRegistry() {
292
315
  registerStoreInstance(storeName, store);
293
316
  return store.store;
294
317
  }
295
- /**
296
- * Subscribe handler to a store.
297
- *
298
- * @param {string|StoreDescriptor} storeNameOrDescriptor The store name.
299
- * @param {Function} handler The function subscribed to the store.
300
- * @return {Function} A function to unsubscribe the handler.
301
- */
302
-
303
-
304
- function __unstableSubscribeStore(storeNameOrDescriptor, handler) {
305
- const storeName = isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
306
- const store = stores[storeName];
307
-
308
- if (store) {
309
- return store.subscribe(handler);
310
- } // Trying to access a store that hasn't been registered,
311
- // this is a pattern rarely used but seen in some places.
312
- // We fallback to regular `subscribe` here for backward-compatibility for now.
313
- // See https://github.com/WordPress/gutenberg/pull/27466 for more info.
314
-
315
-
316
- if (!parent) {
317
- return subscribe(handler);
318
- }
319
-
320
- return parent.__unstableSubscribeStore(storeNameOrDescriptor, handler);
321
- }
322
318
 
323
319
  function batch(callback) {
324
320
  emitter.pause();
@@ -342,8 +338,7 @@ function createRegistry() {
342
338
  register,
343
339
  registerGenericStore,
344
340
  registerStore,
345
- __unstableMarkListeningStores,
346
- __unstableSubscribeStore
341
+ __unstableMarkListeningStores
347
342
  }; //
348
343
  // TODO:
349
344
  // This function will be deprecated as soon as it is no longer internally referenced.