@wordpress/data 6.3.0 → 6.3.1-next.a55ed9455a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/use-select/index.js +1 -1
  3. package/build/components/use-select/index.js.map +1 -1
  4. package/build/factory.js +1 -1
  5. package/build/factory.js.map +1 -1
  6. package/build/plugins/persistence/index.js +114 -12
  7. package/build/plugins/persistence/index.js.map +1 -1
  8. package/build/redux-store/index.js +24 -8
  9. package/build/redux-store/index.js.map +1 -1
  10. package/build/redux-store/metadata/actions.js +47 -4
  11. package/build/redux-store/metadata/actions.js.map +1 -1
  12. package/build/redux-store/metadata/reducer.js +57 -4
  13. package/build/redux-store/metadata/reducer.js.map +1 -1
  14. package/build/redux-store/metadata/selectors.js +71 -7
  15. package/build/redux-store/metadata/selectors.js.map +1 -1
  16. package/build/registry.js +0 -2
  17. package/build/registry.js.map +1 -1
  18. package/build/resolvers-cache-middleware.js +3 -3
  19. package/build/resolvers-cache-middleware.js.map +1 -1
  20. package/build-module/components/use-select/index.js +1 -1
  21. package/build-module/components/use-select/index.js.map +1 -1
  22. package/build-module/factory.js +1 -1
  23. package/build-module/factory.js.map +1 -1
  24. package/build-module/plugins/persistence/index.js +111 -12
  25. package/build-module/plugins/persistence/index.js.map +1 -1
  26. package/build-module/redux-store/index.js +24 -8
  27. package/build-module/redux-store/index.js.map +1 -1
  28. package/build-module/redux-store/metadata/actions.js +43 -4
  29. package/build-module/redux-store/metadata/actions.js.map +1 -1
  30. package/build-module/redux-store/metadata/reducer.js +57 -4
  31. package/build-module/redux-store/metadata/reducer.js.map +1 -1
  32. package/build-module/redux-store/metadata/selectors.js +65 -7
  33. package/build-module/redux-store/metadata/selectors.js.map +1 -1
  34. package/build-module/registry.js +0 -2
  35. package/build-module/registry.js.map +1 -1
  36. package/build-module/resolvers-cache-middleware.js +3 -3
  37. package/build-module/resolvers-cache-middleware.js.map +1 -1
  38. package/build-types/redux-store/metadata/actions.d.ts +37 -4
  39. package/build-types/redux-store/metadata/actions.d.ts.map +1 -1
  40. package/build-types/redux-store/metadata/reducer.d.ts +10 -2
  41. package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
  42. package/build-types/redux-store/metadata/selectors.d.ts +40 -0
  43. package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
  44. package/build-types/types.d.ts.map +1 -1
  45. package/package.json +8 -8
  46. package/src/components/use-select/index.js +1 -1
  47. package/src/components/use-select/test/index.js +7 -7
  48. package/src/components/with-select/test/index.js +3 -3
  49. package/src/factory.js +1 -1
  50. package/src/plugins/persistence/index.js +142 -8
  51. package/src/plugins/persistence/test/index.js +405 -0
  52. package/src/redux-store/index.js +43 -15
  53. package/src/redux-store/metadata/actions.js +43 -4
  54. package/src/redux-store/metadata/reducer.ts +60 -9
  55. package/src/redux-store/metadata/selectors.js +60 -7
  56. package/src/redux-store/metadata/test/reducer.js +64 -24
  57. package/src/redux-store/metadata/test/selectors.js +263 -53
  58. package/src/redux-store/test/index.js +42 -0
  59. package/src/registry.js +0 -2
  60. package/src/resolvers-cache-middleware.js +4 -3
  61. package/src/test/controls.js +7 -7
  62. package/src/test/registry.js +6 -6
  63. package/src/types.ts +1 -3
  64. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,8 @@
7
7
  ### New Features
8
8
 
9
9
  - Enabled thunks by default for all stores and removed the `__experimentalUseThunks` flag.
10
+ - Store the resolution errors in store metadata and expose them using `hasResolutionFailed` the `getResolutionError` meta-selectors ([#38669](https://github.com/WordPress/gutenberg/pull/38669)).
11
+ - Expose the resolution status (undefined, resolving, finished, error) via the `getResolutionState` meta-selector ([#38669](https://github.com/WordPress/gutenberg/pull/38669)).
10
12
 
11
13
  ## 6.2.1 (2022-02-10)
12
14
 
@@ -209,7 +209,7 @@ function useSelect(mapSelect, deps) {
209
209
 
210
210
  forceRender();
211
211
  }
212
- }; // catch any possible state changes during mount before the subscription
212
+ }; // Catch any possible state changes during mount before the subscription
213
213
  // could be set.
214
214
 
215
215
 
@@ -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","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,cA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["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\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\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = 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 trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\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\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\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\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\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\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\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.flush( queueContext );\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, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\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","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAAMC,kBAAkB,GAAG,eAAe,OAAOF,SAAjD,CADoD,CAGpD;AACA;AACA;;AACA,MAAK,CAAEE,kBAAP,EAA4B;AAC3BD,IAAAA,IAAI,GAAG,EAAP;AACA,GARmD,CAUpD;AACA;AACA;AACA;AACA;;;AACA,QAAME,cAAc,GAAG,0BACtBD,kBAAkB,GAAGF,SAAH,GAAeH,IADX,EAEtBI,IAFsB,CAAvB;;AAIA,QAAMG,UAAU,GAAGF,kBAAkB,GAAGC,cAAH,GAAoB,IAAzD;;AAEA,QAAME,QAAQ,GAAG,2BAAjB;AACA,QAAMC,OAAO,GAAG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+BI,KAA/B;AACA;;AACDjB,QAAAA,WAAW;AACX;AACD,KAlBD,CALgC,CAyBhC;AACA;;;AACA,QAAKG,aAAa,CAACU,OAAnB,EAA6B;AAC5BxB,MAAAA,WAAW,CAACqC,GAAZ,CAAiB5B,YAAjB,EAA+B0B,aAA/B;AACA,KAFD,MAEO;AACNA,MAAAA,aAAa;AACb;;AAED,UAAMG,QAAQ,GAAG,MAAM;AACtB,UAAKxB,aAAa,CAACU,OAAnB,EAA6B;AAC5BxB,QAAAA,WAAW,CAACqC,GAAZ,CAAiB5B,YAAjB,EAA+B0B,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAND;;AAQA,UAAMI,aAAa,GAAGrB,eAAe,CAACM,OAAhB,CAAwBgB,GAAxB,CAA+BC,SAAF,IAClDlC,QAAQ,CAACmC,4BAAT,CAAuCD,SAAvC,EAAkDH,QAAlD,CADqB,CAAtB;AAIA,WAAO,MAAM;AACZrB,MAAAA,4BAA4B,CAACO,OAA7B,GAAuC,KAAvC,CADY,CAEZ;;AACAe,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA5C,MAAAA,WAAW,CAACkC,KAAZ,CAAmBzB,YAAnB;AACA,KALD,CA7CgC,CAmDhC;AACA;AACA;AACA,GAtDD,EAsDG,CAAEF,QAAF,EAAYY,UAAZ,EAAwBf,kBAAxB,EAA4CkB,eAA5C,CAtDH;AAwDA,SAAOlB,kBAAkB,GAAGmB,SAAH,GAAehB,QAAQ,CAACoB,MAAT,CAAiBzB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\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\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = 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 trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\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\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\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\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\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\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\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.flush( queueContext );\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, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
package/build/factory.js CHANGED
@@ -44,7 +44,7 @@ exports.createRegistrySelector = createRegistrySelector;
44
44
  * @return {Function} Registry selector that can be registered with a store.
45
45
  */
46
46
  function createRegistrySelector(registrySelector) {
47
- // create a selector function that is bound to the registry referenced by `selector.registry`
47
+ // Create a selector function that is bound to the registry referenced by `selector.registry`
48
48
  // and that has the same API as a regular selector. Binding it in such a way makes it
49
49
  // possible to call the selector directly from another selector.
50
50
  const selector = function () {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.createPersistenceInterface = createPersistenceInterface;
9
9
  exports.default = void 0;
10
10
  exports.migrateFeaturePreferencesToInterfaceStore = migrateFeaturePreferencesToInterfaceStore;
11
+ exports.migrateFeaturePreferencesToPreferencesStore = migrateFeaturePreferencesToPreferencesStore;
12
+ exports.migrateIndividualPreferenceToPreferencesStore = migrateIndividualPreferenceToPreferencesStore;
11
13
  exports.withLazySameState = void 0;
12
14
 
13
15
  var _lodash = require("lodash");
@@ -227,6 +229,108 @@ function persistencePlugin(registry, pluginOptions) {
227
229
 
228
230
  };
229
231
  }
232
+ /**
233
+ * Move the 'features' object in local storage from the sourceStoreName to the
234
+ * preferences store.
235
+ *
236
+ * @param {Object} persistence The persistence interface.
237
+ * @param {string} sourceStoreName The name of the store that has persisted
238
+ * preferences to migrate to the preferences
239
+ * package.
240
+ */
241
+
242
+
243
+ function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreName) {
244
+ var _state$interfaceStore, _state$interfaceStore2, _state$interfaceStore3, _state$sourceStoreNam, _state$sourceStoreNam2;
245
+
246
+ const preferencesStoreName = 'core/preferences';
247
+ const interfaceStoreName = 'core/interface';
248
+ const state = persistence.get(); // Features most recently (and briefly) lived in the interface package.
249
+ // If data exists there, prioritize using that for the migration. If not
250
+ // also check the original package as the user may have updated from an
251
+ // older block editor version.
252
+
253
+ const interfaceFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : (_state$interfaceStore3 = _state$interfaceStore2.features) === null || _state$interfaceStore3 === void 0 ? void 0 : _state$interfaceStore3[sourceStoreName];
254
+ const sourceFeatures = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2.features;
255
+ const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
256
+
257
+ if (featuresToMigrate) {
258
+ var _state$preferencesSto;
259
+
260
+ const targetFeatures = (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated.
261
+
262
+ if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
263
+ // Set the feature values in the interface store, the features
264
+ // object is keyed by 'scope', which matches the store name for
265
+ // the source.
266
+ persistence.set(preferencesStoreName, {
267
+ preferences: { ...targetFeatures,
268
+ [sourceStoreName]: featuresToMigrate
269
+ }
270
+ }); // Remove migrated feature preferences from `interface`.
271
+
272
+ if (interfaceFeatures) {
273
+ var _state$interfaceStore4, _state$interfaceStore5;
274
+
275
+ const otherInterfaceFeatures = (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features;
276
+ persistence.set(interfaceStoreName, {
277
+ preferences: {
278
+ features: { ...otherInterfaceFeatures,
279
+ [sourceStoreName]: undefined
280
+ }
281
+ }
282
+ });
283
+ } // Remove migrated feature preferences from the source.
284
+
285
+
286
+ if (sourceFeatures) {
287
+ var _state$sourceStoreNam3;
288
+
289
+ const sourcePreferences = (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences;
290
+ persistence.set(sourceStoreName, {
291
+ preferences: { ...sourcePreferences,
292
+ features: undefined
293
+ }
294
+ });
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ function migrateIndividualPreferenceToPreferencesStore(persistence, sourceStoreName, key) {
301
+ var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6;
302
+
303
+ const preferencesStoreName = 'core/preferences';
304
+ const state = persistence.get();
305
+ const sourcePreference = (_state$sourceStoreNam4 = state[sourceStoreName]) === null || _state$sourceStoreNam4 === void 0 ? void 0 : (_state$sourceStoreNam5 = _state$sourceStoreNam4.preferences) === null || _state$sourceStoreNam5 === void 0 ? void 0 : _state$sourceStoreNam5[key]; // There's nothing to migrate, exit early.
306
+
307
+ if (!sourcePreference) {
308
+ return;
309
+ }
310
+
311
+ const targetPreference = (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2.preferences) === null || _state$preferencesSto3 === void 0 ? void 0 : (_state$preferencesSto4 = _state$preferencesSto3[sourceStoreName]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4[key]; // There's existing data at the target, so don't overwrite it, exit early.
312
+
313
+ if (targetPreference) {
314
+ return;
315
+ }
316
+
317
+ const allPreferences = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences;
318
+ const targetPreferences = (_state$preferencesSto6 = state[preferencesStoreName]) === null || _state$preferencesSto6 === void 0 ? void 0 : (_state$preferencesSto7 = _state$preferencesSto6.preferences) === null || _state$preferencesSto7 === void 0 ? void 0 : _state$preferencesSto7[sourceStoreName];
319
+ persistence.set(preferencesStoreName, {
320
+ preferences: { ...allPreferences,
321
+ [sourceStoreName]: { ...targetPreferences,
322
+ [key]: sourcePreference
323
+ }
324
+ }
325
+ }); // Remove migrated feature preferences from the source.
326
+
327
+ const allSourcePreferences = (_state$sourceStoreNam6 = state[sourceStoreName]) === null || _state$sourceStoreNam6 === void 0 ? void 0 : _state$sourceStoreNam6.preferences;
328
+ persistence.set(sourceStoreName, {
329
+ preferences: { ...allSourcePreferences,
330
+ [key]: undefined
331
+ }
332
+ });
333
+ }
230
334
  /**
231
335
  * Move the 'features' object in local storage from the sourceStoreName to the
232
336
  * interface store.
@@ -239,17 +343,17 @@ function persistencePlugin(registry, pluginOptions) {
239
343
 
240
344
 
241
345
  function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName) {
242
- var _state$sourceStoreNam;
346
+ var _state$sourceStoreNam7;
243
347
 
244
348
  const interfaceStoreName = 'core/interface';
245
349
  const state = persistence.get();
246
- const sourcePreferences = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : _state$sourceStoreNam.preferences;
350
+ const sourcePreferences = (_state$sourceStoreNam7 = state[sourceStoreName]) === null || _state$sourceStoreNam7 === void 0 ? void 0 : _state$sourceStoreNam7.preferences;
247
351
  const sourceFeatures = sourcePreferences === null || sourcePreferences === void 0 ? void 0 : sourcePreferences.features;
248
352
 
249
353
  if (sourceFeatures) {
250
- var _state$interfaceStore, _state$interfaceStore2;
354
+ var _state$interfaceStore6, _state$interfaceStore7;
251
355
 
252
- const targetFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : _state$interfaceStore2.features; // Avoid migrating features again if they've previously been migrated.
356
+ const targetFeatures = (_state$interfaceStore6 = state[interfaceStoreName]) === null || _state$interfaceStore6 === void 0 ? void 0 : (_state$interfaceStore7 = _state$interfaceStore6.preferences) === null || _state$interfaceStore7 === void 0 ? void 0 : _state$interfaceStore7.features; // Avoid migrating features again if they've previously been migrated.
253
357
 
254
358
  if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
255
359
  // Set the feature values in the interface store, the features
@@ -271,17 +375,15 @@ function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName)
271
375
  }
272
376
  }
273
377
  }
274
- /**
275
- * Deprecated: Remove this function and the code in WordPress Core that calls
276
- * it once WordPress 6.0 is released.
277
- */
278
-
279
378
 
280
379
  persistencePlugin.__unstableMigrate = pluginOptions => {
281
380
  const persistence = createPersistenceInterface(pluginOptions);
282
- migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-widgets');
283
- migrateFeaturePreferencesToInterfaceStore(persistence, 'core/customize-widgets');
284
- migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-post');
381
+ migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-widgets');
382
+ migrateFeaturePreferencesToPreferencesStore(persistence, 'core/customize-widgets');
383
+ migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-post');
384
+ migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-post', 'hiddenBlockTypes');
385
+ migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site');
386
+ migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-site', 'editorMode');
285
387
  };
286
388
 
287
389
  var _default = persistencePlugin;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToInterfaceStore","sourceStoreName","interfaceStoreName","sourcePreferences","preferences","sourceFeatures","features","targetFeatures","__unstableMigrate"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAGC,iBAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,iBAAiB,GAAKC,OAAF,IAAe,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACpE,MAAKA,MAAM,CAACC,SAAP,KAAqBF,KAA1B,EAAkC;AACjC,WAAOA,KAAP;AACA;;AAED,SAAOD,OAAO,CAAEC,KAAF,EAASC,MAAT,CAAd;AACA,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASE,0BAAT,CAAqCC,OAArC,EAA+C;AACrD,QAAM;AACLC,IAAAA,OAAO,GAAGV,eADL;AAELW,IAAAA,UAAU,GAAGT;AAFR,MAGFO,OAHJ;AAKA,MAAIG,IAAJ;AAEA;AACD;AACA;AACA;AACA;;AACC,WAASC,OAAT,GAAmB;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;AACZE,UAAAA,QAAQ,EAAE,EACT,GAAGC,cADM;AAET,aAAEN,eAAF,GAAqBI;AAFZ;AADE;AADuB,OAArC,EAJ4C,CAa5C;;AACA1B,MAAAA,WAAW,CAACJ,GAAZ,CAAiB0B,eAAjB,EAAkC;AACjCG,QAAAA,WAAW,EAAE,EACZ,GAAGD,iBADS;AAEZG,UAAAA,QAAQ,EAAE3C;AAFE;AADoB,OAAlC;AAMA;AACD;AACD;AAED;AACA;AACA;AACA;;;AAEAa,iBAAiB,CAACgC,iBAAlB,GAAwC9B,aAAF,IAAqB;AAC1D,QAAMC,WAAW,GAAGtB,0BAA0B,CAAEqB,aAAF,CAA9C;AAEAsB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,mBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,wBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CAAErB,WAAF,EAAe,gBAAf,CAAzC;AACA,CAZD;;eAceH,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\n/**\n * Deprecated: Remove this function and the code in WordPress Core that calls\n * it once WordPress 6.0 is released.\n */\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );\n};\n\nexport default persistencePlugin;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToPreferencesStore","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","targetFeatures","otherInterfaceFeatures","sourcePreferences","migrateIndividualPreferenceToPreferencesStore","sourcePreference","targetPreference","allPreferences","targetPreferences","allSourcePreferences","migrateFeaturePreferencesToInterfaceStore","__unstableMigrate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AAkC;AACjCI,QAAAA,WAAW,EAAE,EACZ,GAAGM,iBADS;AAEZL,UAAAA,QAAQ,EAAE3C;AAFE;AADoB,OAAlC;AAMA;AACD;AACD;;AAEDa,iBAAiB,CAAC2C,iBAAlB,GAAwCzC,aAAF,IAAqB;AAC1D,QAAMC,WAAW,GAAGtB,0BAA0B,CAAEqB,aAAF,CAA9C;AAEAsB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,mBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,wBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAiC,EAAAA,6CAA6C,CAC5CjC,WAD4C,EAE5C,gBAF4C,EAG5C,kBAH4C,CAA7C;AAKAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAiC,EAAAA,6CAA6C,CAC5CjC,WAD4C,EAE5C,gBAF4C,EAG5C,YAH4C,CAA7C;AAKA,CA7BD;;eA+BeH,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n */\nexport function migrateFeaturePreferencesToPreferencesStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\tconst state = persistence.get();\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate[ interfaceStoreName ]?.preferences?.features?.[ sourceStoreName ];\n\tconst sourceFeatures = state[ sourceStoreName ]?.preferences?.features;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( featuresToMigrate ) {\n\t\tconst targetFeatures = state[ preferencesStoreName ]?.preferences;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( preferencesStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove migrated feature preferences from `interface`.\n\t\t\tif ( interfaceFeatures ) {\n\t\t\t\tconst otherInterfaceFeatures =\n\t\t\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t\t...otherInterfaceFeatures,\n\t\t\t\t\t\t\t[ sourceStoreName ]: undefined,\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\t// Remove migrated feature preferences from the source.\n\t\t\tif ( sourceFeatures ) {\n\t\t\t\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\n\t\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\t\tfeatures: undefined,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function migrateIndividualPreferenceToPreferencesStore(\n\tpersistence,\n\tsourceStoreName,\n\tkey\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst state = persistence.get();\n\tconst sourcePreference = state[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourcePreference ) {\n\t\treturn;\n\t}\n\n\tconst targetPreference =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ]?.[\n\t\t\tkey\n\t\t];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn;\n\t}\n\n\tconst allPreferences = state[ preferencesStoreName ]?.preferences;\n\tconst targetPreferences =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ];\n\n\tpersistence.set( preferencesStoreName, {\n\t\tpreferences: {\n\t\t\t...allPreferences,\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...targetPreferences,\n\t\t\t\t[ key ]: sourcePreference,\n\t\t\t},\n\t\t},\n\t} );\n\n\t// Remove migrated feature preferences from the source.\n\tconst allSourcePreferences = state[ sourceStoreName ]?.preferences;\n\tpersistence.set( sourceStoreName, {\n\t\tpreferences: {\n\t\t\t...allSourcePreferences,\n\t\t\t[ key ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post',\n\t\t'hiddenBlockTypes'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site',\n\t\t'editorMode'\n\t);\n};\n\nexport default persistencePlugin;\n"]}
@@ -332,22 +332,33 @@ function mapResolveSelectors(selectors, store) {
332
332
  args[_key3] = arguments[_key3];
333
333
  }
334
334
 
335
- return new Promise(resolve => {
335
+ return new Promise((resolve, reject) => {
336
336
  const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
337
337
 
338
- const getResult = () => selector.apply(null, args); // trigger the selector (to trigger the resolver)
338
+ const finalize = result => {
339
+ const hasFailed = selectors.hasResolutionFailed(selectorName, args);
340
+
341
+ if (hasFailed) {
342
+ const error = selectors.getResolutionError(selectorName, args);
343
+ reject(error);
344
+ } else {
345
+ resolve(result);
346
+ }
347
+ };
348
+
349
+ const getResult = () => selector.apply(null, args); // Trigger the selector (to trigger the resolver)
339
350
 
340
351
 
341
352
  const result = getResult();
342
353
 
343
354
  if (hasFinished()) {
344
- return resolve(result);
355
+ return finalize(result);
345
356
  }
346
357
 
347
358
  const unsubscribe = store.subscribe(() => {
348
359
  if (hasFinished()) {
349
360
  unsubscribe();
350
- resolve(getResult());
361
+ finalize(getResult());
351
362
  }
352
363
  });
353
364
  });
@@ -375,8 +386,8 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
375
386
  }
376
387
 
377
388
  return { ...resolver,
378
- // copy the enumerable properties of the resolver function
379
- fulfill: resolver // add the fulfill method
389
+ // Copy the enumerable properties of the resolver function.
390
+ fulfill: resolver // Add the fulfill method.
380
391
 
381
392
  };
382
393
  });
@@ -413,8 +424,13 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
413
424
  setTimeout(async () => {
414
425
  resolversCache.clear(selectorName, args);
415
426
  store.dispatch(metadataActions.startResolution(selectorName, args));
416
- await fulfillResolver(store, mappedResolvers, selectorName, ...args);
417
- store.dispatch(metadataActions.finishResolution(selectorName, args));
427
+
428
+ try {
429
+ await fulfillResolver(store, mappedResolvers, selectorName, ...args);
430
+ store.dispatch(metadataActions.finishResolution(selectorName, args));
431
+ } catch (error) {
432
+ store.dispatch(metadataActions.failResolution(selectorName, args, error));
433
+ }
418
434
  });
419
435
  }
420
436
 
@@ -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","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","hasFinished","hasFinishedResolution","getResult","apply","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAtBA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;;AASA;;AACA;;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAAP,GAAgB,CAA9B,EAAiCD,CAAC,IAAI,CAAtC,EAAyCA,CAAC,EAA1C,EAA+C;AAC9C,QAAKD,MAAM,CAAEC,CAAF,CAAN,KAAgBE,SAArB,EAAiC;AAChCH,MAAAA,MAAM,CAACI,MAAP,CAAeH,CAAf,EAAkB,CAAlB;AACA;AACD;;AACD,SAAOD,MAAP;AACA,CARD;AAUA;AACA;AACA;AACA;AACA;;;AACA,SAASK,oBAAT,GAAgC;AAC/B,QAAMC,KAAK,GAAG,EAAd;AACA,SAAO;AACNC,IAAAA,SAAS,CAAEC,YAAF,EAAgBC,IAAhB,EAAuB;AAC/B,aACCH,KAAK,CAAEE,YAAF,CAAL,IACAF,KAAK,CAAEE,YAAF,CAAL,CAAsBE,GAAtB,CAA2BZ,mBAAmB,CAAEW,IAAF,CAA9C,CAFD;AAIA,KANK;;AAQNE,IAAAA,KAAK,CAAEH,YAAF,EAAgBC,IAAhB,EAAuB;AAC3B,UAAKH,KAAK,CAAEE,YAAF,CAAV,EAA6B;AAC5BF,QAAAA,KAAK,CAAEE,YAAF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,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAEgF,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAP/E,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMkB,MAAM,GAAG6D,QAAQ,CAACC,OAAT,CAAkB,GAAGhF,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 { flowRight, get, mapValues, omit } 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';\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/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\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 * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} 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 ) => ( state, ...args ) =>\n\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\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\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\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\tflowRight( 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 = ( action ) => ( ...args ) => {\n\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\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\treturn mapValues(\n\t\tomit( selectors, [\n\t\t\t'getIsResolving',\n\t\t\t'hasStartedResolution',\n\t\t\t'hasFinishedResolution',\n\t\t\t'isResolving',\n\t\t\t'getCachedResolvers',\n\t\t] ),\n\t\t( selector, selectorName ) => ( ...args ) =>\n\t\t\tnew Promise( ( resolve ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\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 resolve( 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\tresolve( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\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\tawait fulfillResolver(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t...args\n\t\t\t\t\t);\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.finishResolution( selectorName, args )\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","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","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","reject","hasFinished","hasFinishedResolution","finalize","hasFailed","hasResolutionFailed","error","getResolutionError","getResult","apply","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAtBA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;;AASA;;AACA;;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAA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AAhB,CAAjB;;AACA,MAAK,CAAEsF,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPrF,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMkB,MAAM,GAAGmE,QAAQ,CAACC,OAAT,CAAkB,GAAGtF,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 { flowRight, get, mapValues, omit } 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';\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/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\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 * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} 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 ) => ( state, ...args ) =>\n\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\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\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\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\tflowRight( 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 = ( action ) => ( ...args ) => {\n\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\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\treturn mapValues(\n\t\tomit( selectors, [\n\t\t\t'getIsResolving',\n\t\t\t'hasStartedResolution',\n\t\t\t'hasFinishedResolution',\n\t\t\t'isResolving',\n\t\t\t'getCachedResolvers',\n\t\t] ),\n\t\t( selector, selectorName ) => ( ...args ) =>\n\t\t\tnew 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);\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"]}