@wordpress/data 10.31.1-next.f56bd8138.0 → 10.32.1-next.47f435fc9.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 (158) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/async-mode-provider/context.js +35 -54
  3. package/build/components/async-mode-provider/context.js.map +7 -1
  4. package/build/components/async-mode-provider/index.js +40 -25
  5. package/build/components/async-mode-provider/index.js.map +7 -1
  6. package/build/components/async-mode-provider/use-async-mode.js +25 -16
  7. package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
  8. package/build/components/registry-provider/context.js +46 -64
  9. package/build/components/registry-provider/context.js.map +7 -1
  10. package/build/components/registry-provider/index.js +40 -25
  11. package/build/components/registry-provider/index.js.map +7 -1
  12. package/build/components/registry-provider/use-registry.js +25 -55
  13. package/build/components/registry-provider/use-registry.js.map +7 -1
  14. package/build/components/use-dispatch/index.js +38 -17
  15. package/build/components/use-dispatch/index.js.map +7 -1
  16. package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
  17. package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
  18. package/build/components/use-dispatch/use-dispatch.js +36 -71
  19. package/build/components/use-dispatch/use-dispatch.js.map +7 -1
  20. package/build/components/use-select/index.js +79 -208
  21. package/build/components/use-select/index.js.map +7 -1
  22. package/build/components/with-dispatch/index.js +34 -107
  23. package/build/components/with-dispatch/index.js.map +7 -1
  24. package/build/components/with-registry/index.js +30 -30
  25. package/build/components/with-registry/index.js.map +7 -1
  26. package/build/components/with-select/index.js +44 -67
  27. package/build/components/with-select/index.js.map +7 -1
  28. package/build/controls.js +49 -110
  29. package/build/controls.js.map +7 -1
  30. package/build/create-selector.js +36 -11
  31. package/build/create-selector.js.map +7 -1
  32. package/build/default-registry.js +24 -10
  33. package/build/default-registry.js.map +7 -1
  34. package/build/dispatch.js +38 -31
  35. package/build/dispatch.js.map +7 -1
  36. package/build/factory.js +29 -85
  37. package/build/factory.js.map +7 -1
  38. package/build/index.js +114 -301
  39. package/build/index.js.map +7 -1
  40. package/build/lock-unlock.js +31 -14
  41. package/build/lock-unlock.js.map +7 -1
  42. package/build/plugins/index.js +36 -11
  43. package/build/plugins/index.js.map +7 -1
  44. package/build/plugins/persistence/index.js +74 -139
  45. package/build/plugins/persistence/index.js.map +7 -1
  46. package/build/plugins/persistence/storage/default.js +37 -18
  47. package/build/plugins/persistence/storage/default.js.map +7 -1
  48. package/build/plugins/persistence/storage/object.js +24 -7
  49. package/build/plugins/persistence/storage/object.js.map +7 -1
  50. package/build/promise-middleware.js +37 -20
  51. package/build/promise-middleware.js.map +7 -1
  52. package/build/redux-store/combine-reducers.js +26 -5
  53. package/build/redux-store/combine-reducers.js.map +7 -1
  54. package/build/redux-store/index.js +221 -331
  55. package/build/redux-store/index.js.map +7 -1
  56. package/build/redux-store/metadata/actions.js +51 -112
  57. package/build/redux-store/metadata/actions.js.map +7 -1
  58. package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
  59. package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
  60. package/build/redux-store/metadata/reducer.js +111 -115
  61. package/build/redux-store/metadata/reducer.js.map +7 -1
  62. package/build/redux-store/metadata/selectors.js +109 -181
  63. package/build/redux-store/metadata/selectors.js.map +7 -1
  64. package/build/redux-store/metadata/utils.js +32 -35
  65. package/build/redux-store/metadata/utils.js.map +7 -1
  66. package/build/redux-store/thunk-middleware.js +24 -7
  67. package/build/redux-store/thunk-middleware.js.map +7 -1
  68. package/build/registry.js +94 -198
  69. package/build/registry.js.map +7 -1
  70. package/build/resolvers-cache-middleware.js +26 -27
  71. package/build/resolvers-cache-middleware.js.map +7 -1
  72. package/build/select.js +38 -31
  73. package/build/select.js.map +7 -1
  74. package/build/store/index.js +52 -16
  75. package/build/store/index.js.map +7 -1
  76. package/build/types.js +16 -5
  77. package/build/types.js.map +7 -1
  78. package/build/utils/emitter.js +33 -16
  79. package/build/utils/emitter.js.map +7 -1
  80. package/build-module/components/async-mode-provider/context.js +12 -49
  81. package/build-module/components/async-mode-provider/context.js.map +7 -1
  82. package/build-module/components/async-mode-provider/index.js +8 -3
  83. package/build-module/components/async-mode-provider/index.js.map +7 -1
  84. package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
  85. package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
  86. package/build-module/components/registry-provider/context.js +13 -58
  87. package/build-module/components/registry-provider/context.js.map +7 -1
  88. package/build-module/components/registry-provider/index.js +8 -3
  89. package/build-module/components/registry-provider/index.js.map +7 -1
  90. package/build-module/components/registry-provider/use-registry.js +7 -51
  91. package/build-module/components/registry-provider/use-registry.js.map +7 -1
  92. package/build-module/components/use-dispatch/index.js +7 -3
  93. package/build-module/components/use-dispatch/index.js.map +7 -1
  94. package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
  95. package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
  96. package/build-module/components/use-dispatch/use-dispatch.js +8 -66
  97. package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
  98. package/build-module/components/use-select/index.js +45 -193
  99. package/build-module/components/use-select/index.js.map +7 -1
  100. package/build-module/components/with-dispatch/index.js +16 -104
  101. package/build-module/components/with-dispatch/index.js.map +7 -1
  102. package/build-module/components/with-registry/index.js +12 -27
  103. package/build-module/components/with-registry/index.js.map +7 -1
  104. package/build-module/components/with-select/index.js +16 -63
  105. package/build-module/components/with-select/index.js.map +7 -1
  106. package/build-module/controls.js +25 -105
  107. package/build-module/controls.js.map +7 -1
  108. package/build-module/create-selector.js +5 -8
  109. package/build-module/create-selector.js.map +7 -1
  110. package/build-module/default-registry.js +6 -6
  111. package/build-module/default-registry.js.map +7 -1
  112. package/build-module/dispatch.js +6 -27
  113. package/build-module/dispatch.js.map +7 -1
  114. package/build-module/factory.js +8 -82
  115. package/build-module/factory.js.map +7 -1
  116. package/build-module/index.js +62 -185
  117. package/build-module/index.js.map +7 -1
  118. package/build-module/lock-unlock.js +8 -7
  119. package/build-module/lock-unlock.js.map +7 -1
  120. package/build-module/plugins/index.js +5 -2
  121. package/build-module/plugins/index.js.map +7 -1
  122. package/build-module/plugins/persistence/index.js +38 -129
  123. package/build-module/plugins/persistence/index.js.map +7 -1
  124. package/build-module/plugins/persistence/storage/default.js +8 -11
  125. package/build-module/plugins/persistence/storage/default.js.map +7 -1
  126. package/build-module/plugins/persistence/storage/object.js +6 -3
  127. package/build-module/plugins/persistence/storage/object.js.map +7 -1
  128. package/build-module/promise-middleware.js +8 -14
  129. package/build-module/promise-middleware.js.map +7 -1
  130. package/build-module/redux-store/combine-reducers.js +5 -2
  131. package/build-module/redux-store/combine-reducers.js.map +7 -1
  132. package/build-module/redux-store/index.js +180 -310
  133. package/build-module/redux-store/index.js.map +7 -1
  134. package/build-module/redux-store/metadata/actions.js +30 -109
  135. package/build-module/redux-store/metadata/actions.js.map +7 -1
  136. package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
  137. package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
  138. package/build-module/redux-store/metadata/reducer.js +83 -108
  139. package/build-module/redux-store/metadata/reducer.js.map +7 -1
  140. package/build-module/redux-store/metadata/selectors.js +76 -175
  141. package/build-module/redux-store/metadata/selectors.js.map +7 -1
  142. package/build-module/redux-store/metadata/utils.js +10 -30
  143. package/build-module/redux-store/metadata/utils.js.map +7 -1
  144. package/build-module/redux-store/thunk-middleware.js +7 -4
  145. package/build-module/redux-store/thunk-middleware.js.map +7 -1
  146. package/build-module/registry.js +56 -187
  147. package/build-module/registry.js.map +7 -1
  148. package/build-module/resolvers-cache-middleware.js +8 -23
  149. package/build-module/resolvers-cache-middleware.js.map +7 -1
  150. package/build-module/select.js +6 -27
  151. package/build-module/select.js.map +7 -1
  152. package/build-module/store/index.js +34 -12
  153. package/build-module/store/index.js.map +7 -1
  154. package/build-module/types.js +1 -2
  155. package/build-module/types.js.map +7 -1
  156. package/build-module/utils/emitter.js +12 -13
  157. package/build-module/utils/emitter.js.map +7 -1
  158. package/package.json +17 -10
package/build/dispatch.js CHANGED
@@ -1,35 +1,42 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var dispatch_exports = {};
30
+ __export(dispatch_exports, {
31
+ dispatch: () => dispatch
6
32
  });
7
- exports.dispatch = dispatch;
8
- var _defaultRegistry = _interopRequireDefault(require("./default-registry"));
9
- /**
10
- * Internal dependencies
11
- */
12
-
13
- /**
14
- * Given a store descriptor, returns an object of the store's action creators.
15
- * Calling an action creator will cause it to be dispatched, updating the state value accordingly.
16
- *
17
- * Note: Action creators returned by the dispatch will return a promise when
18
- * they are called.
19
- *
20
- * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing
21
- * the store name is also supported.
22
- *
23
- * @example
24
- * ```js
25
- * import { dispatch } from '@wordpress/data';
26
- * import { store as myCustomStore } from 'my-custom-store';
27
- *
28
- * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
29
- * ```
30
- * @return Object containing the action creators.
31
- */
33
+ module.exports = __toCommonJS(dispatch_exports);
34
+ var import_default_registry = __toESM(require("./default-registry"));
32
35
  function dispatch(storeNameOrDescriptor) {
33
- return _defaultRegistry.default.dispatch(storeNameOrDescriptor);
36
+ return import_default_registry.default.dispatch(storeNameOrDescriptor);
34
37
  }
35
- //# sourceMappingURL=dispatch.js.map
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ dispatch
41
+ });
42
+ //# sourceMappingURL=dispatch.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_defaultRegistry","_interopRequireDefault","require","dispatch","storeNameOrDescriptor","defaultRegistry"],"sources":["@wordpress/data/src/dispatch.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch( storeNameOrDescriptor );\n}\n"],"mappings":";;;;;;;AAIA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CAGvBC,qBAA4C,EACF;EAC1C,OAAOC,wBAAe,CAACF,QAAQ,CAAEC,qBAAsB,CAAC;AACzD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dispatch.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch( storeNameOrDescriptor );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA4B;AAqBrB,SAAS,SAGf,uBAC0C;AAC1C,SAAO,wBAAAA,QAAgB,SAAU,qBAAsB;AACxD;",
6
+ "names": ["defaultRegistry"]
7
+ }
package/build/factory.js CHANGED
@@ -1,103 +1,47 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var factory_exports = {};
20
+ __export(factory_exports, {
21
+ createRegistryControl: () => createRegistryControl,
22
+ createRegistrySelector: () => createRegistrySelector
5
23
  });
6
- exports.createRegistryControl = createRegistryControl;
7
- exports.createRegistrySelector = createRegistrySelector;
8
- /**
9
- * Internal dependencies
10
- */
11
-
12
- /**
13
- * Creates a selector function that takes additional curried argument with the
14
- * registry `select` function. While a regular selector has signature
15
- * ```js
16
- * ( state, ...selectorArgs ) => ( result )
17
- * ```
18
- * that allows to select data from the store's `state`, a registry selector
19
- * has signature:
20
- * ```js
21
- * ( select ) => ( state, ...selectorArgs ) => ( result )
22
- * ```
23
- * that supports also selecting from other registered stores.
24
- *
25
- * @example
26
- * ```js
27
- * import { store as coreStore } from '@wordpress/core-data';
28
- * import { store as editorStore } from '@wordpress/editor';
29
- *
30
- * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
31
- * return select( editorStore ).getCurrentPostId();
32
- * } );
33
- *
34
- * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
35
- * // calling another registry selector just like any other function
36
- * const postType = getCurrentPostType( state );
37
- * const postId = getCurrentPostId( state );
38
- * return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );
39
- * } );
40
- * ```
41
- *
42
- * Note how the `getCurrentPostId` selector can be called just like any other function,
43
- * (it works even inside a regular non-registry selector) and we don't need to pass the
44
- * registry as argument. The registry binding happens automatically when registering the selector
45
- * with a store.
46
- *
47
- * @param registrySelector Function receiving a registry `select`
48
- * function and returning a state selector.
49
- *
50
- * @return Registry selector that can be registered with a store.
51
- */
24
+ module.exports = __toCommonJS(factory_exports);
52
25
  function createRegistrySelector(registrySelector) {
53
- const selectorsByRegistry = new WeakMap();
54
- // Create a selector function that is bound to the registry referenced by `selector.registry`
55
- // and that has the same API as a regular selector. Binding it in such a way makes it
56
- // possible to call the selector directly from another selector.
26
+ const selectorsByRegistry = /* @__PURE__ */ new WeakMap();
57
27
  const wrappedSelector = (...args) => {
58
28
  let selector = selectorsByRegistry.get(wrappedSelector.registry);
59
- // We want to make sure the cache persists even when new registry
60
- // instances are created. For example patterns create their own editors
61
- // with their own core/block-editor stores, so we should keep track of
62
- // the cache for each registry instance.
63
29
  if (!selector) {
64
30
  selector = registrySelector(wrappedSelector.registry.select);
65
31
  selectorsByRegistry.set(wrappedSelector.registry, selector);
66
32
  }
67
33
  return selector(...args);
68
34
  };
69
-
70
- /**
71
- * Flag indicating that the selector is a registry selector that needs the correct registry
72
- * reference to be assigned to `selector.registry` to make it work correctly.
73
- * be mapped as a registry selector.
74
- */
75
35
  wrappedSelector.isRegistrySelector = true;
76
36
  return wrappedSelector;
77
37
  }
78
-
79
- /**
80
- * Creates a control function that takes additional curried argument with the `registry` object.
81
- * While a regular control has signature
82
- * ```js
83
- * ( action ) => ( iteratorOrPromise )
84
- * ```
85
- * where the control works with the `action` that it's bound to, a registry control has signature:
86
- * ```js
87
- * ( registry ) => ( action ) => ( iteratorOrPromise )
88
- * ```
89
- * A registry control is typically used to select data or dispatch an action to a registered
90
- * store.
91
- *
92
- * When registering a control created with `createRegistryControl` with a store, the store
93
- * knows which calling convention to use when executing the control.
94
- *
95
- * @param registryControl Function receiving a registry object and returning a control.
96
- *
97
- * @return Registry control that can be registered with a store.
98
- */
99
38
  function createRegistryControl(registryControl) {
100
39
  registryControl.isRegistryControl = true;
101
40
  return registryControl;
102
41
  }
103
- //# sourceMappingURL=factory.js.map
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ createRegistryControl,
45
+ createRegistrySelector
46
+ });
47
+ //# sourceMappingURL=factory.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createRegistrySelector","registrySelector","selectorsByRegistry","WeakMap","wrappedSelector","args","selector","get","registry","select","set","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"sources":["@wordpress/data/src/factory.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl< T extends ( ...args: any ) => any >(\n\tregistryControl: T & { isRegistryControl?: boolean }\n) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,sBAAsBA,CAGrCC,gBAA6D,EAC9B;EAC/B,MAAMC,mBAAmB,GAAG,IAAIC,OAAO,CAAC,CAAC;EACzC;EACA;EACA;EACA,MAAMC,eAA6C,GAAGA,CAAE,GAAGC,IAAI,KAAM;IACpE,IAAIC,QAAQ,GAAGJ,mBAAmB,CAACK,GAAG,CAAEH,eAAe,CAACI,QAAS,CAAC;IAClE;IACA;IACA;IACA;IACA,IAAK,CAAEF,QAAQ,EAAG;MACjBA,QAAQ,GAAGL,gBAAgB,CAAEG,eAAe,CAACI,QAAQ,CAACC,MAAO,CAAC;MAC9DP,mBAAmB,CAACQ,GAAG,CAAEN,eAAe,CAACI,QAAQ,EAAEF,QAAS,CAAC;IAC9D;IACA,OAAOA,QAAQ,CAAE,GAAGD,IAAK,CAAC;EAC3B,CAAC;;EAED;AACD;AACA;AACA;AACA;EACCD,eAAe,CAACO,kBAAkB,GAAG,IAAI;EAEzC,OAAOP,eAAe;AACvB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,qBAAqBA,CACpCC,eAAoD,EACnD;EACDA,eAAe,CAACC,iBAAiB,GAAG,IAAI;EAExC,OAAOD,eAAe;AACvB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/factory.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl< T extends ( ...args: any ) => any >(\n\tregistryControl: T & { isRegistryControl?: boolean }\n) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDO,SAAS,uBAGf,kBAC+B;AAC/B,QAAM,sBAAsB,oBAAI,QAAQ;AAIxC,QAAM,kBAAgD,IAAK,SAAU;AACpE,QAAI,WAAW,oBAAoB,IAAK,gBAAgB,QAAS;AAKjE,QAAK,CAAE,UAAW;AACjB,iBAAW,iBAAkB,gBAAgB,SAAS,MAAO;AAC7D,0BAAoB,IAAK,gBAAgB,UAAU,QAAS;AAAA,IAC7D;AACA,WAAO,SAAU,GAAG,IAAK;AAAA,EAC1B;AAOA,kBAAgB,qBAAqB;AAErC,SAAO;AACR;AAsBO,SAAS,sBACf,iBACC;AACD,kBAAgB,oBAAoB;AAEpC,SAAO;AACR;",
6
+ "names": []
7
+ }