@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
@@ -1,51 +1,53 @@
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 use_select_exports = {};
30
+ __export(use_select_exports, {
31
+ default: () => useSelect,
32
+ useSuspenseSelect: () => useSuspenseSelect
6
33
  });
7
- exports.default = useSelect;
8
- exports.useSuspenseSelect = useSuspenseSelect;
9
- var _priorityQueue = require("@wordpress/priority-queue");
10
- var _element = require("@wordpress/element");
11
- var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equal"));
12
- var _useRegistry = _interopRequireDefault(require("../registry-provider/use-registry"));
13
- var _useAsyncMode = _interopRequireDefault(require("../async-mode-provider/use-async-mode"));
14
- /**
15
- * WordPress dependencies
16
- */
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
-
22
- const renderQueue = (0, _priorityQueue.createQueue)();
34
+ module.exports = __toCommonJS(use_select_exports);
35
+ var import_priority_queue = require("@wordpress/priority-queue");
36
+ var import_element = require("@wordpress/element");
37
+ var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
38
+ var import_use_registry = __toESM(require("../registry-provider/use-registry"));
39
+ var import_use_async_mode = __toESM(require("../async-mode-provider/use-async-mode"));
40
+ const renderQueue = (0, import_priority_queue.createQueue)();
23
41
  function warnOnUnstableReference(a, b) {
24
42
  if (!a || !b) {
25
43
  return;
26
44
  }
27
- const keys = typeof a === 'object' && typeof b === 'object' ? Object.keys(a).filter(k => a[k] !== b[k]) : [];
28
-
29
- // eslint-disable-next-line no-console
30
- console.warn('The `useSelect` hook returns different values when called with the same state and parameters.\n' + 'This can lead to unnecessary re-renders and performance issues if not fixed.\n\n' + 'Non-equal value keys: %s\n\n', keys.join(', '));
45
+ const keys = typeof a === "object" && typeof b === "object" ? Object.keys(a).filter((k) => a[k] !== b[k]) : [];
46
+ console.warn(
47
+ "The `useSelect` hook returns different values when called with the same state and parameters.\nThis can lead to unnecessary re-renders and performance issues if not fixed.\n\nNon-equal value keys: %s\n\n",
48
+ keys.join(", ")
49
+ );
31
50
  }
32
-
33
- /**
34
- * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
35
- * @template {import('../../types').AnyConfig} C
36
- */
37
- /**
38
- * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
39
- * @template State
40
- * @template {Record<string,import('../../types').ActionCreator>} Actions
41
- * @template Selectors
42
- */
43
- /** @typedef {import('../../types').MapSelect} MapSelect */
44
- /**
45
- * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
46
- * @template {MapSelect|StoreDescriptor<any>} T
47
- */
48
-
49
51
  function Store(registry, suspense) {
50
52
  const select = suspense ? registry.suspendSelect : registry.select;
51
53
  const queueContext = {};
@@ -55,31 +57,14 @@ function Store(registry, suspense) {
55
57
  let lastIsAsync;
56
58
  let subscriber;
57
59
  let didWarnUnstableReference;
58
- const storeStatesOnMount = new Map();
60
+ const storeStatesOnMount = /* @__PURE__ */ new Map();
59
61
  function getStoreState(name) {
60
- var _registry$stores$name;
61
- // If there's no store property (custom generic store), return an empty
62
- // object. When comparing the state, the empty objects will cause the
63
- // equality check to fail, setting `lastMapResultValid` to false.
64
- return (_registry$stores$name = registry.stores[name]?.store?.getState?.()) !== null && _registry$stores$name !== void 0 ? _registry$stores$name : {};
62
+ return registry.stores[name]?.store?.getState?.() ?? {};
65
63
  }
66
- const createSubscriber = stores => {
67
- // The set of stores the `subscribe` function is supposed to subscribe to. Here it is
68
- // initialized, and then the `updateStores` function can add new stores to it.
64
+ const createSubscriber = (stores) => {
69
65
  const activeStores = [...stores];
70
-
71
- // The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could
72
- // be called multiple times to establish multiple subscriptions. That's why we need to
73
- // keep a set of active subscriptions;
74
- const activeSubscriptions = new Set();
66
+ const activeSubscriptions = /* @__PURE__ */ new Set();
75
67
  function subscribe(listener) {
76
- // Maybe invalidate the value right after subscription was created.
77
- // React will call `getValue` after subscribing, to detect store
78
- // updates that happened in the interval between the `getValue` call
79
- // during render and creating the subscription, which is slightly
80
- // delayed. We need to ensure that this second `getValue` call will
81
- // compute a fresh value only if any of the store states have
82
- // changed in the meantime.
83
68
  if (lastMapResultValid) {
84
69
  for (const name of activeStores) {
85
70
  if (storeStatesOnMount.get(name) !== getStoreState(name)) {
@@ -89,7 +74,6 @@ function Store(registry, suspense) {
89
74
  }
90
75
  storeStatesOnMount.clear();
91
76
  const onStoreChange = () => {
92
- // Invalidate the value on store update, so that a fresh value is computed.
93
77
  lastMapResultValid = false;
94
78
  listener();
95
79
  };
@@ -111,51 +95,38 @@ function Store(registry, suspense) {
111
95
  return () => {
112
96
  activeSubscriptions.delete(subscribeStore);
113
97
  for (const unsub of unsubs.values()) {
114
- // The return value of the subscribe function could be undefined if the store is a custom generic store.
115
98
  unsub?.();
116
99
  }
117
- // Cancel existing store updates that were already scheduled.
118
100
  renderQueue.cancel(queueContext);
119
101
  };
120
102
  }
121
-
122
- // Check if `newStores` contains some stores we're not subscribed to yet, and add them.
123
103
  function updateStores(newStores) {
124
104
  for (const newStore of newStores) {
125
105
  if (activeStores.includes(newStore)) {
126
106
  continue;
127
107
  }
128
-
129
- // New `subscribe` calls will subscribe to `newStore`, too.
130
108
  activeStores.push(newStore);
131
-
132
- // Add `newStore` to existing subscriptions.
133
109
  for (const subscription of activeSubscriptions) {
134
110
  subscription(newStore);
135
111
  }
136
112
  }
137
113
  }
138
- return {
139
- subscribe,
140
- updateStores
141
- };
114
+ return { subscribe, updateStores };
142
115
  };
143
116
  return (mapSelect, isAsync) => {
144
117
  function updateValue() {
145
- // If the last value is valid, and the `mapSelect` callback hasn't changed,
146
- // then we can safely return the cached value. The value can change only on
147
- // store update, and in that case value will be invalidated by the listener.
148
118
  if (lastMapResultValid && mapSelect === lastMapSelect) {
149
119
  return lastMapResult;
150
120
  }
151
- const listeningStores = {
152
- current: null
153
- };
154
- const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores);
121
+ const listeningStores = { current: null };
122
+ const mapResult = registry.__unstableMarkListeningStores(
123
+ () => mapSelect(select, registry),
124
+ listeningStores
125
+ );
155
126
  if (globalThis.SCRIPT_DEBUG) {
156
127
  if (!didWarnUnstableReference) {
157
128
  const secondMapResult = mapSelect(select, registry);
158
- if (!(0, _isShallowEqual.default)(mapResult, secondMapResult)) {
129
+ if (!(0, import_is_shallow_equal.default)(mapResult, secondMapResult)) {
159
130
  warnOnUnstableReference(mapResult, secondMapResult);
160
131
  didWarnUnstableReference = true;
161
132
  }
@@ -169,158 +140,58 @@ function Store(registry, suspense) {
169
140
  } else {
170
141
  subscriber.updateStores(listeningStores.current);
171
142
  }
172
-
173
- // If the new value is shallow-equal to the old one, keep the old one so
174
- // that we don't trigger unwanted updates that do a `===` check.
175
- if (!(0, _isShallowEqual.default)(lastMapResult, mapResult)) {
143
+ if (!(0, import_is_shallow_equal.default)(lastMapResult, mapResult)) {
176
144
  lastMapResult = mapResult;
177
145
  }
178
146
  lastMapSelect = mapSelect;
179
147
  lastMapResultValid = true;
180
148
  }
181
149
  function getValue() {
182
- // Update the value in case it's been invalidated or `mapSelect` has changed.
183
150
  updateValue();
184
151
  return lastMapResult;
185
152
  }
186
-
187
- // When transitioning from async to sync mode, cancel existing store updates
188
- // that have been scheduled, and invalidate the value so that it's freshly
189
- // computed. It might have been changed by the update we just cancelled.
190
153
  if (lastIsAsync && !isAsync) {
191
154
  lastMapResultValid = false;
192
155
  renderQueue.cancel(queueContext);
193
156
  }
194
157
  updateValue();
195
158
  lastIsAsync = isAsync;
196
-
197
- // Return a pair of functions that can be passed to `useSyncExternalStore`.
198
- return {
199
- subscribe: subscriber.subscribe,
200
- getValue
201
- };
159
+ return { subscribe: subscriber.subscribe, getValue };
202
160
  };
203
161
  }
204
162
  function _useStaticSelect(storeName) {
205
- return (0, _useRegistry.default)().select(storeName);
163
+ return (0, import_use_registry.default)().select(storeName);
206
164
  }
207
165
  function _useMappingSelect(suspense, mapSelect, deps) {
208
- const registry = (0, _useRegistry.default)();
209
- const isAsync = (0, _useAsyncMode.default)();
210
- const store = (0, _element.useMemo)(() => Store(registry, suspense), [registry, suspense]);
211
-
212
- // These are "pass-through" dependencies from the parent hook,
213
- // and the parent should catch any hook rule violations.
214
- const selector = (0, _element.useCallback)(mapSelect, deps);
215
- const {
216
- subscribe,
217
- getValue
218
- } = store(selector, isAsync);
219
- const result = (0, _element.useSyncExternalStore)(subscribe, getValue, getValue);
220
- (0, _element.useDebugValue)(result);
166
+ const registry = (0, import_use_registry.default)();
167
+ const isAsync = (0, import_use_async_mode.default)();
168
+ const store = (0, import_element.useMemo)(
169
+ () => Store(registry, suspense),
170
+ [registry, suspense]
171
+ );
172
+ const selector = (0, import_element.useCallback)(mapSelect, deps);
173
+ const { subscribe, getValue } = store(selector, isAsync);
174
+ const result = (0, import_element.useSyncExternalStore)(subscribe, getValue, getValue);
175
+ (0, import_element.useDebugValue)(result);
221
176
  return result;
222
177
  }
223
-
224
- /**
225
- * Custom react hook for retrieving props from registered selectors.
226
- *
227
- * In general, this custom React hook follows the
228
- * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).
229
- *
230
- * @template {MapSelect | StoreDescriptor<any>} T
231
- * @param {T} mapSelect Function called on every state change. The returned value is
232
- * exposed to the component implementing this hook. The function
233
- * receives the `registry.select` method on the first argument
234
- * and the `registry` on the second argument.
235
- * When a store key is passed, all selectors for the store will be
236
- * returned. This is only meant for usage of these selectors in event
237
- * callbacks, not for data needed to create the element tree.
238
- * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is
239
- * invoked on every state change unless the dependencies change.
240
- *
241
- * @example
242
- * ```js
243
- * import { useSelect } from '@wordpress/data';
244
- * import { store as myCustomStore } from 'my-custom-store';
245
- *
246
- * function HammerPriceDisplay( { currency } ) {
247
- * const price = useSelect( ( select ) => {
248
- * return select( myCustomStore ).getPrice( 'hammer', currency );
249
- * }, [ currency ] );
250
- * return new Intl.NumberFormat( 'en-US', {
251
- * style: 'currency',
252
- * currency,
253
- * } ).format( price );
254
- * }
255
- *
256
- * // Rendered in the application:
257
- * // <HammerPriceDisplay currency="USD" />
258
- * ```
259
- *
260
- * In the above example, when `HammerPriceDisplay` is rendered into an
261
- * application, the price will be retrieved from the store state using the
262
- * `mapSelect` callback on `useSelect`. If the currency prop changes then
263
- * any price in the state for that currency is retrieved. If the currency prop
264
- * doesn't change and other props are passed in that do change, the price will
265
- * not change because the dependency is just the currency.
266
- *
267
- * When data is only used in an event callback, the data should not be retrieved
268
- * on render, so it may be useful to get the selectors function instead.
269
- *
270
- * **Don't use `useSelect` this way when calling the selectors in the render
271
- * function because your component won't re-render on a data change.**
272
- *
273
- * ```js
274
- * import { useSelect } from '@wordpress/data';
275
- * import { store as myCustomStore } from 'my-custom-store';
276
- *
277
- * function Paste( { children } ) {
278
- * const { getSettings } = useSelect( myCustomStore );
279
- * function onPaste() {
280
- * // Do something with the settings.
281
- * const settings = getSettings();
282
- * }
283
- * return <div onPaste={ onPaste }>{ children }</div>;
284
- * }
285
- * ```
286
- * @return {UseSelectReturn<T>} A custom react hook.
287
- */
288
178
  function useSelect(mapSelect, deps) {
289
- // On initial call, on mount, determine the mode of this `useSelect` call
290
- // and then never allow it to change on subsequent updates.
291
- const staticSelectMode = typeof mapSelect !== 'function';
292
- const staticSelectModeRef = (0, _element.useRef)(staticSelectMode);
179
+ const staticSelectMode = typeof mapSelect !== "function";
180
+ const staticSelectModeRef = (0, import_element.useRef)(staticSelectMode);
293
181
  if (staticSelectMode !== staticSelectModeRef.current) {
294
- const prevMode = staticSelectModeRef.current ? 'static' : 'mapping';
295
- const nextMode = staticSelectMode ? 'static' : 'mapping';
296
- throw new Error(`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`);
182
+ const prevMode = staticSelectModeRef.current ? "static" : "mapping";
183
+ const nextMode = staticSelectMode ? "static" : "mapping";
184
+ throw new Error(
185
+ `Switching useSelect from ${prevMode} to ${nextMode} is not allowed`
186
+ );
297
187
  }
298
-
299
- // `staticSelectMode` is not allowed to change during the hook instance's,
300
- // lifetime, so the rules of hooks are not really violated.
301
188
  return staticSelectMode ? _useStaticSelect(mapSelect) : _useMappingSelect(false, mapSelect, deps);
302
189
  }
303
-
304
- /**
305
- * A variant of the `useSelect` hook that has the same API, but is a compatible
306
- * Suspense-enabled data source.
307
- *
308
- * @template {MapSelect} T
309
- * @param {T} mapSelect Function called on every state change. The
310
- * returned value is exposed to the component
311
- * using this hook. The function receives the
312
- * `registry.suspendSelect` method as the first
313
- * argument and the `registry` as the second one.
314
- * @param {Array} deps A dependency array used to memoize the `mapSelect`
315
- * so that the same `mapSelect` is invoked on every
316
- * state change unless the dependencies change.
317
- *
318
- * @throws {Promise} A suspense Promise that is thrown if any of the called
319
- * selectors is in an unresolved state.
320
- *
321
- * @return {ReturnType<T>} Data object returned by the `mapSelect` function.
322
- */
323
190
  function useSuspenseSelect(mapSelect, deps) {
324
191
  return _useMappingSelect(true, mapSelect, deps);
325
192
  }
326
- //# sourceMappingURL=index.js.map
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ useSuspenseSelect
196
+ });
197
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_priorityQueue","require","_element","_isShallowEqual","_interopRequireDefault","_useRegistry","_useAsyncMode","renderQueue","createQueue","warnOnUnstableReference","a","b","keys","Object","filter","k","console","warn","join","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","didWarnUnstableReference","storeStatesOnMount","Map","getStoreState","name","_registry$stores$name","stores","store","getState","createSubscriber","activeStores","activeSubscriptions","Set","subscribe","listener","get","clear","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","globalThis","SCRIPT_DEBUG","secondMapResult","isShallowEqual","set","getValue","_useStaticSelect","useRegistry","_useMappingSelect","deps","useAsyncMode","useMemo","selector","useCallback","result","useSyncExternalStore","useDebugValue","useSelect","staticSelectMode","staticSelectModeRef","useRef","prevMode","nextMode","Error","useSuspenseSelect"],"sources":["@wordpress/data/src/components/use-select/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference( a, b ) {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\tlet didWarnUnstableReference;\n\tconst storeStatesOnMount = new Map();\n\n\tfunction getStoreState( name ) {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? _useStaticSelect( mapSelect )\n\t\t: _useMappingSelect( false, mapSelect, deps );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @template {MapSelect} T\n * @param {T} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws {Promise} A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return {ReturnType<T>} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn _useMappingSelect( true, mapSelect, deps );\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAOA,IAAAE,eAAA,GAAAC,sBAAA,CAAAH,OAAA;AAKA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AAjBA;AACA;AACA;;AAWA;AACA;AACA;;AAIA,MAAMM,WAAW,GAAG,IAAAC,0BAAW,EAAC,CAAC;AAEjC,SAASC,uBAAuBA,CAAEC,CAAC,EAAEC,CAAC,EAAG;EACxC,IAAK,CAAED,CAAC,IAAI,CAAEC,CAAC,EAAG;IACjB;EACD;EAEA,MAAMC,IAAI,G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,SAAS,EAAEgB,IAAK,CAAC;AAClD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/use-select/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference( a, b ) {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\tlet didWarnUnstableReference;\n\tconst storeStatesOnMount = new Map();\n\n\tfunction getStoreState( name ) {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? _useStaticSelect( mapSelect )\n\t\t: _useMappingSelect( false, mapSelect, deps );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @template {MapSelect} T\n * @param {T} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws {Promise} A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return {ReturnType<T>} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn _useMappingSelect( true, mapSelect, deps );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAA4B;AAC5B,qBAMO;AACP,8BAA2B;AAK3B,0BAAwB;AACxB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Registry", "useAsyncMode"]
7
+ }
@@ -1,109 +1,36 @@
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 with_dispatch_exports = {};
20
+ __export(with_dispatch_exports, {
21
+ default: () => with_dispatch_default
5
22
  });
6
- exports.default = void 0;
7
- var _compose = require("@wordpress/compose");
8
- var _useDispatch = require("../use-dispatch");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /** @typedef {import('react').ComponentType} ComponentType */
19
-
20
- /**
21
- * Higher-order component used to add dispatch props using registered action
22
- * creators.
23
- *
24
- * @param {Function} mapDispatchToProps A function of returning an object of
25
- * prop names where value is a
26
- * dispatch-bound action creator, or a
27
- * function to be called with the
28
- * component's props and returning an
29
- * action creator.
30
- *
31
- * @example
32
- * ```jsx
33
- * function Button( { onClick, children } ) {
34
- * return <button type="button" onClick={ onClick }>{ children }</button>;
35
- * }
36
- *
37
- * import { withDispatch } from '@wordpress/data';
38
- * import { store as myCustomStore } from 'my-custom-store';
39
- *
40
- * const SaleButton = withDispatch( ( dispatch, ownProps ) => {
41
- * const { startSale } = dispatch( myCustomStore );
42
- * const { discountPercent } = ownProps;
43
- *
44
- * return {
45
- * onClick() {
46
- * startSale( discountPercent );
47
- * },
48
- * };
49
- * } )( Button );
50
- *
51
- * // Rendered in the application:
52
- * //
53
- * // <SaleButton discountPercent="20">Start Sale!</SaleButton>
54
- * ```
55
- *
56
- * @example
57
- * In the majority of cases, it will be sufficient to use only two first params
58
- * passed to `mapDispatchToProps` as illustrated in the previous example.
59
- * However, there might be some very advanced use cases where using the
60
- * `registry` object might be used as a tool to optimize the performance of
61
- * your component. Using `select` function from the registry might be useful
62
- * when you need to fetch some dynamic data from the store at the time when the
63
- * event is fired, but at the same time, you never use it to render your
64
- * component. In such scenario, you can avoid using the `withSelect` higher
65
- * order component to compute such prop, which might lead to unnecessary
66
- * re-renders of your component caused by its frequent value change.
67
- * Keep in mind, that `mapDispatchToProps` must return an object with functions
68
- * only.
69
- *
70
- * ```jsx
71
- * function Button( { onClick, children } ) {
72
- * return <button type="button" onClick={ onClick }>{ children }</button>;
73
- * }
74
- *
75
- * import { withDispatch } from '@wordpress/data';
76
- * import { store as myCustomStore } from 'my-custom-store';
77
- *
78
- * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
79
- * // Stock number changes frequently.
80
- * const { getStockNumber } = select( myCustomStore );
81
- * const { startSale } = dispatch( myCustomStore );
82
- * return {
83
- * onClick() {
84
- * const discountPercent = getStockNumber() > 50 ? 10 : 20;
85
- * startSale( discountPercent );
86
- * },
87
- * };
88
- * } )( Button );
89
- *
90
- * // Rendered in the application:
91
- * //
92
- * // <SaleButton>Start Sale!</SaleButton>
93
- * ```
94
- *
95
- * _Note:_ It is important that the `mapDispatchToProps` function always
96
- * returns an object with the same keys. For example, it should not contain
97
- * conditions under which a different value would be returned.
98
- *
99
- * @return {ComponentType} Enhanced component with merged dispatcher props.
100
- */const withDispatch = mapDispatchToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => ownProps => {
101
- const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
102
- const dispatchProps = (0, _useDispatch.useDispatchWithMap)(mapDispatch, []);
103
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
104
- ...ownProps,
105
- ...dispatchProps
106
- });
107
- }, 'withDispatch');
108
- var _default = exports.default = withDispatch;
109
- //# sourceMappingURL=index.js.map
23
+ module.exports = __toCommonJS(with_dispatch_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_compose = require("@wordpress/compose");
26
+ var import_use_dispatch = require("../use-dispatch");
27
+ const withDispatch = (mapDispatchToProps) => (0, import_compose.createHigherOrderComponent)(
28
+ (WrappedComponent) => (ownProps) => {
29
+ const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
30
+ const dispatchProps = (0, import_use_dispatch.useDispatchWithMap)(mapDispatch, []);
31
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...ownProps, ...dispatchProps });
32
+ },
33
+ "withDispatch"
34
+ );
35
+ var with_dispatch_default = withDispatch;
36
+ //# sourceMappingURL=index.js.map