@wordpress/data 6.0.1 → 6.1.3

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 (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +31 -2
  3. package/build/components/registry-provider/use-registry.js +1 -1
  4. package/build/components/registry-provider/use-registry.js.map +1 -1
  5. package/build/controls.js +23 -15
  6. package/build/controls.js.map +1 -1
  7. package/build/plugins/persistence/index.js +43 -50
  8. package/build/plugins/persistence/index.js.map +1 -1
  9. package/build/redux-store/index.js +15 -3
  10. package/build/redux-store/index.js.map +1 -1
  11. package/build/registry.js +40 -7
  12. package/build/registry.js.map +1 -1
  13. package/build/types.js +2 -0
  14. package/build/{types.d.js.map → types.js.map} +0 -0
  15. package/build/utils/emitter.js +57 -0
  16. package/build/utils/emitter.js.map +1 -0
  17. package/build-module/components/registry-provider/use-registry.js +1 -1
  18. package/build-module/components/registry-provider/use-registry.js.map +1 -1
  19. package/build-module/controls.js +22 -15
  20. package/build-module/controls.js.map +1 -1
  21. package/build-module/plugins/persistence/index.js +42 -51
  22. package/build-module/plugins/persistence/index.js.map +1 -1
  23. package/build-module/redux-store/index.js +15 -3
  24. package/build-module/redux-store/index.js.map +1 -1
  25. package/build-module/registry.js +40 -8
  26. package/build-module/registry.js.map +1 -1
  27. package/build-module/types.js +2 -0
  28. package/build-module/{types.d.js.map → types.js.map} +0 -0
  29. package/build-module/utils/emitter.js +50 -0
  30. package/build-module/utils/emitter.js.map +1 -0
  31. package/build-types/redux-store/metadata/selectors.d.ts +1 -3
  32. package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
  33. package/build-types/types.d.ts +35 -0
  34. package/build-types/types.d.ts.map +1 -0
  35. package/build-types/utils/emitter.d.ts +7 -0
  36. package/build-types/utils/emitter.d.ts.map +1 -0
  37. package/package.json +6 -6
  38. package/src/components/registry-provider/use-registry.js +1 -1
  39. package/src/controls.js +43 -15
  40. package/src/plugins/persistence/index.js +56 -62
  41. package/src/plugins/persistence/test/index.js +117 -1
  42. package/src/redux-store/index.js +17 -4
  43. package/src/registry.js +38 -8
  44. package/src/test/registry.js +34 -0
  45. package/src/{types.d.ts → types.ts} +8 -0
  46. package/src/utils/emitter.js +46 -0
  47. package/tsconfig.json +2 -0
  48. package/tsconfig.tsbuildinfo +1 -826
  49. package/build/types.d.js +0 -2
  50. package/build-module/types.d.js +0 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.1.0 (2021-09-09)
6
+
7
+ ### New Features
8
+
9
+ - Added a `batch` registry method to batch dispatch calls for performance reasons.
10
+ - Add a new migration for the persistence plugin to migrate edit-widgets preferences to the interface package. As part of this change deprecated migrations for the persistence plugin have been removed ([#33774](https://github.com/WordPress/gutenberg/pull/33774)).
11
+ - Update data controls to accept a data store definition as their first param in addition to a string-based store name value ([#34170](https://github.com/WordPress/gutenberg/pull/34170)).
12
+
5
13
  ## 6.0.0 (2021-07-29)
6
14
 
7
15
  ### Breaking Change
package/README.md CHANGED
@@ -12,7 +12,7 @@ Install the module
12
12
  npm install @wordpress/data --save
13
13
  ```
14
14
 
15
- _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as IE browsers then using [core-js](https://github.com/zloirock/core-js) will add polyfills for these methods._
15
+ _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
16
16
 
17
17
  ## Registering a Store
18
18
 
@@ -746,7 +746,7 @@ import { RegistryProvider, createRegistry, useRegistry } from '@wordpress/data';
746
746
  const registry = createRegistry( {} );
747
747
 
748
748
  const SomeChildUsingRegistry = ( props ) => {
749
- const registry = useRegistry( registry );
749
+ const registry = useRegistry();
750
750
  // ...logic implementing the registry in other react hooks.
751
751
  };
752
752
 
@@ -973,6 +973,35 @@ _Returns_
973
973
 
974
974
  <!-- END TOKEN(Autogenerated API docs) -->
975
975
 
976
+ ### batch
977
+
978
+ As a response of `dispatch` calls, WordPress data based applications updates the connected components (Components using `useSelect` or `withSelect`). This update happens in two steps:
979
+
980
+ - The selectors are called with the update state.
981
+ - If the selectors return values that are different than the previous (strict equality), the component rerenders.
982
+
983
+ As the application grows, this can become costful, so it's important to ensure that we avoid running both these if possible. One of these situations happen when an interaction requires multiple consisecutive `dispatch` calls in order to update the state properly. To avoid rerendering the components each time we call `dispatch`, we can wrap the sequential dispatch calls in `batch` which will ensure that the components only call selectors and rerender once at the end of the sequence.
984
+
985
+ _Usage_
986
+
987
+ ```js
988
+ import { useRegistry } from '@wordpress/data';
989
+
990
+ function Component() {
991
+ const registry = useRegistry();
992
+
993
+ function callback() {
994
+ // This will only rerender the components once.
995
+ registry.batch( () => {
996
+ registry.dispatch( someStore ).someAction();
997
+ registry.dispatch( someStore ).someOtherAction();
998
+ } );
999
+ }
1000
+
1001
+ return <button onClick={ callback }>Click me</button>;
1002
+ }
1003
+ ```
1004
+
976
1005
  ## Going further
977
1006
 
978
1007
  - [What is WordPress Data?](https://unfoldingneurons.com/2020/what-is-wordpress-data/)
@@ -42,7 +42,7 @@ var _context = require("./context");
42
42
  * const registry = createRegistry( {} );
43
43
  *
44
44
  * const SomeChildUsingRegistry = ( props ) => {
45
- * const registry = useRegistry( registry );
45
+ * const registry = useRegistry();
46
46
  * // ...logic implementing the registry in other react hooks.
47
47
  * };
48
48
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"names":["useRegistry","Context"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,GAAuB;AACrC,SAAO,yBAAYC,gBAAZ,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\n/**\n * A custom react hook exposing the registry context for use.\n *\n * This exposes the `registry` value provided via the\n * <a href=\"#RegistryProvider\">Registry Provider</a> to a component implementing\n * this hook.\n *\n * It acts similarly to the `useContext` react hook.\n *\n * Note: Generally speaking, `useRegistry` is a low level hook that in most cases\n * won't be needed for implementation. Most interactions with the `@wordpress/data`\n * API can be performed via the `useSelect` hook, or the `withSelect` and\n * `withDispatch` higher order components.\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * createRegistry,\n * useRegistry,\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const SomeChildUsingRegistry = ( props ) => {\n * const registry = useRegistry( registry );\n * // ...logic implementing the registry in other react hooks.\n * };\n *\n *\n * const ParentProvidingRegistry = ( props ) => {\n * return <RegistryProvider value={ registry }>\n * <SomeChildUsingRegistry { ...props } />\n * </RegistryProvider>\n * };\n * ```\n *\n * @return {Function} A custom react hook exposing the registry context value.\n */\nexport default function useRegistry() {\n\treturn useContext( Context );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"names":["useRegistry","Context"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,GAAuB;AACrC,SAAO,yBAAYC,gBAAZ,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\n/**\n * A custom react hook exposing the registry context for use.\n *\n * This exposes the `registry` value provided via the\n * <a href=\"#RegistryProvider\">Registry Provider</a> to a component implementing\n * this hook.\n *\n * It acts similarly to the `useContext` react hook.\n *\n * Note: Generally speaking, `useRegistry` is a low level hook that in most cases\n * won't be needed for implementation. Most interactions with the `@wordpress/data`\n * API can be performed via the `useSelect` hook, or the `withSelect` and\n * `withDispatch` higher order components.\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * createRegistry,\n * useRegistry,\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const SomeChildUsingRegistry = ( props ) => {\n * const registry = useRegistry();\n * // ...logic implementing the registry in other react hooks.\n * };\n *\n *\n * const ParentProvidingRegistry = ( props ) => {\n * return <RegistryProvider value={ registry }>\n * <SomeChildUsingRegistry { ...props } />\n * </RegistryProvider>\n * };\n * ```\n *\n * @return {Function} A custom react hook exposing the registry context value.\n */\nexport default function useRegistry() {\n\treturn useContext( Context );\n}\n"]}
package/build/controls.js CHANGED
@@ -5,11 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.builtinControls = exports.controls = void 0;
7
7
 
8
+ var _lodash = require("lodash");
9
+
8
10
  var _factory = require("./factory");
9
11
 
12
+ /**
13
+ * External dependencies
14
+ */
15
+
10
16
  /**
11
17
  * Internal dependencies
12
18
  */
19
+
20
+ /** @typedef {import('./types').WPDataStore} WPDataStore */
13
21
  const SELECT = '@@data/SELECT';
14
22
  const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
15
23
  const DISPATCH = '@@data/DISPATCH';
@@ -19,9 +27,9 @@ const DISPATCH = '@@data/DISPATCH';
19
27
  * Note: This control synchronously returns the current selector value, triggering the
20
28
  * resolution, but not waiting for it.
21
29
  *
22
- * @param {string} storeKey The key for the store the selector belongs to.
23
- * @param {string} selectorName The name of the selector.
24
- * @param {Array} args Arguments for the selector.
30
+ * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store
31
+ * @param {string} selectorName The name of the selector.
32
+ * @param {Array} args Arguments for the selector.
25
33
  *
26
34
  * @example
27
35
  * ```js
@@ -37,10 +45,10 @@ const DISPATCH = '@@data/DISPATCH';
37
45
  * @return {Object} The control descriptor.
38
46
  */
39
47
 
40
- function select(storeKey, selectorName, ...args) {
48
+ function select(storeNameOrDefinition, selectorName, ...args) {
41
49
  return {
42
50
  type: SELECT,
43
- storeKey,
51
+ storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
44
52
  selectorName,
45
53
  args
46
54
  };
@@ -52,9 +60,9 @@ function select(storeKey, selectorName, ...args) {
52
60
  * selectors that may have a resolver. In such case, it will return a `Promise` that resolves
53
61
  * after the selector finishes resolving, with the final result value.
54
62
  *
55
- * @param {string} storeKey The key for the store the selector belongs to
56
- * @param {string} selectorName The name of the selector
57
- * @param {Array} args Arguments for the selector.
63
+ * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store
64
+ * @param {string} selectorName The name of the selector
65
+ * @param {Array} args Arguments for the selector.
58
66
  *
59
67
  * @example
60
68
  * ```js
@@ -71,10 +79,10 @@ function select(storeKey, selectorName, ...args) {
71
79
  */
72
80
 
73
81
 
74
- function resolveSelect(storeKey, selectorName, ...args) {
82
+ function resolveSelect(storeNameOrDefinition, selectorName, ...args) {
75
83
  return {
76
84
  type: RESOLVE_SELECT,
77
- storeKey,
85
+ storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
78
86
  selectorName,
79
87
  args
80
88
  };
@@ -82,9 +90,9 @@ function resolveSelect(storeKey, selectorName, ...args) {
82
90
  /**
83
91
  * Dispatches a control action for triggering a registry dispatch.
84
92
  *
85
- * @param {string} storeKey The key for the store the action belongs to
86
- * @param {string} actionName The name of the action to dispatch
87
- * @param {Array} args Arguments for the dispatch action.
93
+ * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store
94
+ * @param {string} actionName The name of the action to dispatch
95
+ * @param {Array} args Arguments for the dispatch action.
88
96
  *
89
97
  * @example
90
98
  * ```js
@@ -101,10 +109,10 @@ function resolveSelect(storeKey, selectorName, ...args) {
101
109
  */
102
110
 
103
111
 
104
- function dispatch(storeKey, actionName, ...args) {
112
+ function dispatch(storeNameOrDefinition, actionName, ...args) {
105
113
  return {
106
114
  type: DISPATCH,
107
- storeKey,
115
+ storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
108
116
  actionName,
109
117
  args
110
118
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeKey","selectorName","args","type","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,MAAT,CAAiBC,QAAjB,EAA2BC,YAA3B,EAAyC,GAAGC,IAA5C,EAAmD;AAClD,SAAO;AAAEC,IAAAA,IAAI,EAAEP,MAAR;AAAgBI,IAAAA,QAAhB;AAA0BC,IAAAA,YAA1B;AAAwCC,IAAAA;AAAxC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASE,aAAT,CAAwBJ,QAAxB,EAAkCC,YAAlC,EAAgD,GAAGC,IAAnD,EAA0D;AACzD,SAAO;AAAEC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AF,KACfO,QAAQ,CAACJ,QAAT,CAAmBL,QAAnB,EAA+BM,UAA/B,EAA6C,GAAGJ,IAAhD,CAFY;AAdgB,CAAxB","sourcesContent":["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string} storeKey The key for the store the selector belongs to.\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeKey, selectorName, ...args ) {\n\treturn { type: SELECT, storeKey, selectorName, args };\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string} storeKey The key for the store the selector belongs to\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeKey, selectorName, ...args ) {\n\treturn { type: RESOLVE_SELECT, storeKey, selectorName, args };\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string} storeKey The key for the store the action belongs to\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeKey, actionName, ...args ) {\n\treturn { type: DISPATCH, storeKey, actionName, args };\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) =>\n\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) => {\n\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t.hasResolver\n\t\t\t\t? 'resolveSelect'\n\t\t\t\t: 'select';\n\t\t\treturn registry[ method ]( storeKey )[ selectorName ]( ...args );\n\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, actionName, args } ) =>\n\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDefinition","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,E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6BH,YAA7B,EAA6C,GAAGC,IAAhD,CAFU,CADkB;AAK9B,GAAEL,cAAF,GAAoB,oCACjBc,QAAF,IAAgB,CAAE;AAAEP,IAAAA,QAAF;AAAYH,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAF,KAAwC;AACvD,UAAMU,MAAM,GAAGD,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EACbY,WADa,GAEZ,eAFY,GAGZ,QAHH;AAIA,WAAOF,QAAQ,CAAEC,MAAF,CAAR,CAAoBR,QAApB,EAAgCH,YAAhC,EAAgD,GAAGC,IAAnD,CAAP;AACA,GAPkB,CALU;AAc9B,GAAEJ,QAAF,GAAc,oCACXa,QAAF,IAAgB,CAAE;AAAEP,IAAAA,QAAF;AAAYI,IAAAA,UAAZ;AAAwBN,IAAAA;AAAxB,GAAF,KACfS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CAFY;AAdgB,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport { isObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDefinition, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) =>\n\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) => {\n\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t.hasResolver\n\t\t\t\t? 'resolveSelect'\n\t\t\t\t: 'select';\n\t\t\treturn registry[ method ]( storeKey )[ selectorName ]( ...args );\n\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, actionName, args } ) =>\n\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.createPersistenceInterface = createPersistenceInterface;
9
+ exports.migrateFeaturePreferencesToInterfaceStore = migrateFeaturePreferencesToInterfaceStore;
9
10
  exports.default = exports.withLazySameState = void 0;
10
11
 
11
12
  var _lodash = require("lodash");
@@ -226,68 +227,60 @@ function persistencePlugin(registry, pluginOptions) {
226
227
  };
227
228
  }
228
229
  /**
229
- * Deprecated: Remove this function and the code in WordPress Core that calls
230
- * it once WordPress 5.4 is released.
230
+ * Move the 'features' object in local storage from the sourceStoreName to the
231
+ * interface store.
232
+ *
233
+ * @param {Object} persistence The persistence interface.
234
+ * @param {string} sourceStoreName The name of the store that has persisted
235
+ * preferences to migrate to the interface
236
+ * package.
231
237
  */
232
238
 
233
239
 
234
- persistencePlugin.__unstableMigrate = pluginOptions => {
235
- var _state$coreEditor, _state$coreEditor$pre;
240
+ function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName) {
241
+ var _state$sourceStoreNam;
236
242
 
237
- const persistence = createPersistenceInterface(pluginOptions);
238
- const state = persistence.get(); // Migrate 'insertUsage' from 'core/editor' to 'core/block-editor'
243
+ const interfaceStoreName = 'core/interface';
244
+ const state = persistence.get();
245
+ const sourcePreferences = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : _state$sourceStoreNam.preferences;
246
+ const sourceFeatures = sourcePreferences === null || sourcePreferences === void 0 ? void 0 : sourcePreferences.features;
239
247
 
240
- const editorInsertUsage = (_state$coreEditor = state['core/editor']) === null || _state$coreEditor === void 0 ? void 0 : (_state$coreEditor$pre = _state$coreEditor.preferences) === null || _state$coreEditor$pre === void 0 ? void 0 : _state$coreEditor$pre.insertUsage;
248
+ if (sourceFeatures) {
249
+ var _state$interfaceStore, _state$interfaceStore2;
241
250
 
242
- if (editorInsertUsage) {
243
- var _state$coreBlockEdi, _state$coreBlockEdi$p;
251
+ 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.
244
252
 
245
- const blockEditorInsertUsage = (_state$coreBlockEdi = state['core/block-editor']) === null || _state$coreBlockEdi === void 0 ? void 0 : (_state$coreBlockEdi$p = _state$coreBlockEdi.preferences) === null || _state$coreBlockEdi$p === void 0 ? void 0 : _state$coreBlockEdi$p.insertUsage;
246
- persistence.set('core/block-editor', {
247
- preferences: {
248
- insertUsage: { ...editorInsertUsage,
249
- ...blockEditorInsertUsage
253
+ if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
254
+ // Set the feature values in the interface store, the features
255
+ // object is keyed by 'scope', which matches the store name for
256
+ // the source.
257
+ persistence.set(interfaceStoreName, {
258
+ preferences: {
259
+ features: { ...targetFeatures,
260
+ [sourceStoreName]: sourceFeatures
261
+ }
250
262
  }
251
- }
252
- });
253
- }
263
+ }); // Remove feature preferences from the source.
254
264
 
255
- let editPostState = state['core/edit-post']; // Default `fullscreenMode` to `false` if any persisted state had existed
256
- // and the user hadn't made an explicit choice about fullscreen mode. This
257
- // is needed since `fullscreenMode` previously did not have a default value
258
- // and was implicitly false by its absence. It is now `true` by default, but
259
- // this change is not intended to affect upgrades from earlier versions.
260
-
261
- const hadPersistedState = Object.keys(state).length > 0;
262
- const hadFullscreenModePreference = (0, _lodash.has)(state, ['core/edit-post', 'preferences', 'features', 'fullscreenMode']);
263
-
264
- if (hadPersistedState && !hadFullscreenModePreference) {
265
- editPostState = (0, _lodash.merge)({}, editPostState, {
266
- preferences: {
267
- features: {
268
- fullscreenMode: false
265
+ persistence.set(sourceStoreName, {
266
+ preferences: { ...sourcePreferences,
267
+ features: undefined
269
268
  }
270
- }
271
- });
272
- } // Migrate 'areTipsEnabled' from 'core/nux' to 'showWelcomeGuide' in 'core/edit-post'
273
-
274
-
275
- const areTipsEnabled = (0, _lodash.get)(state, ['core/nux', 'preferences', 'areTipsEnabled']);
276
- const hasWelcomeGuide = (0, _lodash.has)(state, ['core/edit-post', 'preferences', 'features', 'welcomeGuide']);
277
-
278
- if (areTipsEnabled !== undefined && !hasWelcomeGuide) {
279
- editPostState = (0, _lodash.merge)({}, editPostState, {
280
- preferences: {
281
- features: {
282
- welcomeGuide: areTipsEnabled
283
- }
284
- }
285
- });
269
+ });
270
+ }
286
271
  }
272
+ }
273
+ /**
274
+ * Deprecated: Remove this function and the code in WordPress Core that calls
275
+ * it once WordPress 6.0 is released.
276
+ */
287
277
 
288
- if (editPostState !== state['core/edit-post']) {
289
- persistence.set('core/edit-post', editPostState);
290
- }
278
+
279
+ persistencePlugin.__unstableMigrate = pluginOptions => {
280
+ const persistence = createPersistenceInterface(pluginOptions);
281
+ migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-widgets');
282
+ migrateFeaturePreferencesToInterfaceStore(persistence, 'core/customize-widgets');
283
+ migrateFeaturePreferencesToInterfaceStore(persistence, 'core/edit-post');
291
284
  };
292
285
 
293
286
  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","__unstableMigrate","editorInsertUsage","preferences","insertUsage","blockEditorInsertUsage","editPostState","hadPersistedState","length","hadFullscreenModePreference","features","fullscreenMode","areTipsEnabled","hasWelcomeGuide","welcomeGuide"],"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;AAClB,QAAKD,IAAI,KAA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;AACA;AACA;AACA;;AACA,QAAMoD,iBAAiB,GAAGhB,MAAM,CAACP,IAAP,CAAa7B,KAAb,EAAqBqD,MAArB,GAA8B,CAAxD;AACA,QAAMC,2BAA2B,GAAG,iBAAKtD,KAAL,EAAY,CAC/C,gBAD+C,EAE/C,aAF+C,EAG/C,UAH+C,EAI/C,gBAJ+C,CAAZ,CAApC;;AAMA,MAAKoD,iBAAiB,IAAI,CAAEE,2BAA5B,EAA0D;AACzDH,IAAAA,aAAa,GAAG,mBAAO,EAAP,EAAWA,aAAX,EAA0B;AACzCH,MAAAA,WAAW,EAAE;AAAEO,QAAAA,QAAQ,EAAE;AAAEC,UAAAA,cAAc,EAAE;AAAlB;AAAZ;AAD4B,KAA1B,CAAhB;AAGA,GAtCyD,CAwC1D;;;AACA,QAAMC,cAAc,GAAG,iBAAKzD,KAAL,EAAY,CAClC,UADkC,EAElC,aAFkC,EAGlC,gBAHkC,CAAZ,CAAvB;AAKA,QAAM0D,eAAe,GAAG,iBAAK1D,KAAL,EAAY,CACnC,gBADmC,EAEnC,aAFmC,EAGnC,UAHmC,EAInC,cAJmC,CAAZ,CAAxB;;AAMA,MAAKyD,cAAc,KAAKhD,SAAnB,IAAgC,CAAEiD,eAAvC,EAAyD;AACxDP,IAAAA,aAAa,GAAG,mBAAO,EAAP,EAAWA,aAAX,EAA0B;AACzCH,MAAAA,WAAW,EAAE;AACZO,QAAAA,QAAQ,EAAE;AACTI,UAAAA,YAAY,EAAEF;AADL;AADE;AAD4B,KAA1B,CAAhB;AAOA;;AAED,MAAKN,aAAa,KAAKnD,KAAK,CAAE,gBAAF,CAA5B,EAAmD;AAClDyB,IAAAA,WAAW,CAACJ,GAAZ,CAAiB,gBAAjB,EAAmC8B,aAAnC;AACA;AACD,CAjED;;eAmEe7B,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject, get, has } 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 * Deprecated: Remove this function and the code in WordPress Core that calls\n * it once WordPress 5.4 is released.\n */\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tconst state = persistence.get();\n\n\t// Migrate 'insertUsage' from 'core/editor' to 'core/block-editor'\n\tconst editorInsertUsage = state[ 'core/editor' ]?.preferences?.insertUsage;\n\tif ( editorInsertUsage ) {\n\t\tconst blockEditorInsertUsage =\n\t\t\tstate[ 'core/block-editor' ]?.preferences?.insertUsage;\n\t\tpersistence.set( 'core/block-editor', {\n\t\t\tpreferences: {\n\t\t\t\tinsertUsage: {\n\t\t\t\t\t...editorInsertUsage,\n\t\t\t\t\t...blockEditorInsertUsage,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t}\n\n\tlet editPostState = state[ 'core/edit-post' ];\n\n\t// Default `fullscreenMode` to `false` if any persisted state had existed\n\t// and the user hadn't made an explicit choice about fullscreen mode. This\n\t// is needed since `fullscreenMode` previously did not have a default value\n\t// and was implicitly false by its absence. It is now `true` by default, but\n\t// this change is not intended to affect upgrades from earlier versions.\n\tconst hadPersistedState = Object.keys( state ).length > 0;\n\tconst hadFullscreenModePreference = has( state, [\n\t\t'core/edit-post',\n\t\t'preferences',\n\t\t'features',\n\t\t'fullscreenMode',\n\t] );\n\tif ( hadPersistedState && ! hadFullscreenModePreference ) {\n\t\teditPostState = merge( {}, editPostState, {\n\t\t\tpreferences: { features: { fullscreenMode: false } },\n\t\t} );\n\t}\n\n\t// Migrate 'areTipsEnabled' from 'core/nux' to 'showWelcomeGuide' in 'core/edit-post'\n\tconst areTipsEnabled = get( state, [\n\t\t'core/nux',\n\t\t'preferences',\n\t\t'areTipsEnabled',\n\t] );\n\tconst hasWelcomeGuide = has( state, [\n\t\t'core/edit-post',\n\t\t'preferences',\n\t\t'features',\n\t\t'welcomeGuide',\n\t] );\n\tif ( areTipsEnabled !== undefined && ! hasWelcomeGuide ) {\n\t\teditPostState = merge( {}, editPostState, {\n\t\t\tpreferences: {\n\t\t\t\tfeatures: {\n\t\t\t\t\twelcomeGuide: areTipsEnabled,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t}\n\n\tif ( editPostState !== state[ 'core/edit-post' ] ) {\n\t\tpersistence.set( 'core/edit-post', editPostState );\n\t}\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","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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AL,EAA6C;AAC5C;AACA;AACA;AACAtB,MAAAA,WAAW,CAACJ,GAAZ,CAAiB2B,kBAAjB,EAAqC;AACpCE,QAAAA,WAAW,EAAE;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"]}
@@ -50,22 +50,34 @@ var metadataActions = _interopRequireWildcard(require("./metadata/actions"));
50
50
  /** @typedef {import('../types').WPDataStore} WPDataStore */
51
51
 
52
52
  /** @typedef {import('../types').WPDataReduxStoreConfig} WPDataReduxStoreConfig */
53
+ const trimUndefinedValues = array => {
54
+ const result = [...array];
53
55
 
56
+ for (let i = result.length - 1; i >= 0; i--) {
57
+ if (result[i] === undefined) {
58
+ result.splice(i, 1);
59
+ }
60
+ }
61
+
62
+ return result;
63
+ };
54
64
  /**
55
65
  * Create a cache to track whether resolvers started running or not.
56
66
  *
57
67
  * @return {Object} Resolvers Cache.
58
68
  */
69
+
70
+
59
71
  function createResolversCache() {
60
72
  const cache = {};
61
73
  return {
62
74
  isRunning(selectorName, args) {
63
- return cache[selectorName] && cache[selectorName].get(args);
75
+ return cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args));
64
76
  },
65
77
 
66
78
  clear(selectorName, args) {
67
79
  if (cache[selectorName]) {
68
- cache[selectorName].delete(args);
80
+ cache[selectorName].delete(trimUndefinedValues(args));
69
81
  }
70
82
  },
71
83
 
@@ -74,7 +86,7 @@ function createResolversCache() {
74
86
  cache[selectorName] = new _equivalentKeyMap.default();
75
87
  }
76
88
 
77
- cache[selectorName].set(args, true);
89
+ cache[selectorName].set(trimUndefinedValues(args), true);
78
90
  }
79
91
 
80
92
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["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","result","mapResolvers","resolveSelectors","mapResolveSelectors","getState","subscribe","listener","lastState","hasChanged","controls","builtinControls","normalizedControls","control","isRegistryControl","middlewares","promise","__experimentalUseThunks","push","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","instanceId","initialState","enhancedReducer","metadataReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","length","Array","i","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;AAC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,GAA+B,IAA/B;AACA,WAAOa,gBAAP;AACA,GAtDD;;AAwDA,SAAO;AACNzD,IAAAA,SAAS,EAAEqD,eADL;AAENjD,IAAAA,SAAS,EAAE,uBAAWA,SAAX,EAAsBoD,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeO,eAAf,CAAgCzE,KAAhC,EAAuCU,SAAvC,EAAkD9B,YAAlD,EAAgE,GAAGC,IAAnE,EAA0E;AACzE,QAAMmF,QAAQ,GAAG,iBAAKtD,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAEoF,QAAP,EAAkB;AACjB;AACA;;AAED,QAAMjE,MAAM,GAAGiE,QAAQ,CAACC,OAAT,CAAkB,GAAGpF,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').WPDataRegistry} WPDataRegistry */\n/** @typedef {import('../types').WPDataStore} WPDataStore */\n/** @typedef {import('../types').WPDataReduxStoreConfig} WPDataReduxStoreConfig */\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 cache[ selectorName ] && cache[ selectorName ].get( args );\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( 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( args, true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store definition for the provided Redux store options 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 {WPDataReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {WPDataStore} 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 {WPDataRegistry} 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];\n\n\tif ( options.__experimentalUseThunks ) {\n\t\tmiddlewares.push( createThunkMiddleware( 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\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\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","__experimentalUseThunks","push","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","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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,CACpBtE,KADoB,EAEpB4D,eAFoB,EAGpBhF,YAHoB,EAIpB,GAAGC,IAJiB,CAArB;AAMAmB,UAAAA,KAAK,CAACJ,QAAN,CACCiB,eAAe,CAAC0D,gBAAhB,CAAkC3F,YAAlC,EAAgDC,IAAhD,CADD;AAGA,SAdS,CAAV;AAeA;;AAEDoF,MAAAA,eAAe,CAAE,GAAGpF,IAAL,CAAf;AACA,aAAOsB,QAAQ,CAAE,GAAGtB,IAAL,CAAf;AACA,KA7CD;;AA8CAmF,IAAAA,gBAAgB,CAACb,WAAjB,GAA+B,IAA/B;AACA,WAAOa,gBAAP;AACA,GAvDD;;AAyDA,SAAO;AACNtD,IAAAA,SAAS,EAAEkD,eADL;AAEN9C,IAAAA,SAAS,EAAE,uBAAWA,SAAX,EAAsBiD,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeO,eAAf,CAAgCtE,KAAhC,EAAuCU,SAAvC,EAAkD9B,YAAlD,EAAgE,GAAGC,IAAnE,EAA0E;AACzE,QAAMgF,QAAQ,GAAG,iBAAKnD,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAEiF,QAAP,EAAkB;AACjB;AACA;;AAED,QAAM9D,MAAM,GAAG8D,QAAQ,CAACC,OAAT,CAAkB,GAAGjF,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').WPDataRegistry} WPDataRegistry */\n/** @typedef {import('../types').WPDataStore} WPDataStore */\n/** @typedef {import('../types').WPDataReduxStoreConfig} WPDataReduxStoreConfig */\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 definition for the provided Redux store options 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 {WPDataReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {WPDataStore} 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 {WPDataRegistry} 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];\n\n\tif ( options.__experimentalUseThunks ) {\n\t\tmiddlewares.push( createThunkMiddleware( 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"]}