@wordpress/data 9.8.0 → 9.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -4
- package/README.md +101 -2
- package/build/components/async-mode-provider/context.js +2 -3
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/async-mode-provider/index.js +0 -5
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.js +1 -3
- package/build/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build/components/registry-provider/context.js +3 -6
- package/build/components/registry-provider/context.js.map +1 -1
- package/build/components/registry-provider/index.js +0 -5
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/registry-provider/use-registry.js +0 -3
- package/build/components/registry-provider/use-registry.js.map +1 -1
- package/build/components/use-dispatch/index.js +0 -3
- package/build/components/use-dispatch/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +0 -7
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +0 -5
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +35 -53
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +2 -7
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +2 -5
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +2 -8
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +4 -10
- package/build/controls.js.map +1 -1
- package/build/default-registry.js +0 -3
- package/build/default-registry.js.map +1 -1
- package/build/dispatch.js +0 -3
- package/build/dispatch.js.map +1 -1
- package/build/factory.js +2 -5
- package/build/factory.js.map +1 -1
- package/build/index.js +7 -28
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/plugins/index.js +0 -2
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/persistence/index.js +13 -37
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/plugins/persistence/storage/default.js +1 -5
- package/build/plugins/persistence/storage/default.js.map +1 -1
- package/build/plugins/persistence/storage/object.js +0 -5
- package/build/plugins/persistence/storage/object.js.map +1 -1
- package/build/promise-middleware.js +0 -5
- package/build/promise-middleware.js.map +1 -1
- package/build/redux-store/index.js +36 -117
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +8 -17
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +1 -23
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +8 -22
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +6 -14
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/redux-store/thunk-middleware.js +0 -2
- package/build/redux-store/thunk-middleware.js.map +1 -1
- package/build/registry.js +29 -73
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +2 -8
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/select.js +0 -3
- package/build/select.js.map +1 -1
- package/build/store/index.js +0 -7
- package/build/store/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils/emitter.js +2 -11
- package/build/utils/emitter.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +1 -1
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/async-mode-provider/index.js.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build-module/components/registry-provider/context.js +3 -3
- package/build-module/components/registry-provider/context.js.map +1 -1
- package/build-module/components/registry-provider/index.js.map +1 -1
- package/build-module/components/registry-provider/use-registry.js +2 -2
- package/build-module/components/registry-provider/use-registry.js.map +1 -1
- package/build-module/components/use-dispatch/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -4
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +1 -3
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +35 -46
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +4 -6
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +4 -4
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +4 -6
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +4 -8
- package/build-module/controls.js.map +1 -1
- package/build-module/default-registry.js.map +1 -1
- package/build-module/dispatch.js +2 -1
- package/build-module/dispatch.js.map +1 -1
- package/build-module/factory.js +2 -3
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +11 -10
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +15 -30
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/plugins/persistence/storage/default.js +0 -2
- package/build-module/plugins/persistence/storage/default.js.map +1 -1
- package/build-module/plugins/persistence/storage/object.js +0 -5
- package/build-module/plugins/persistence/storage/object.js.map +1 -1
- package/build-module/promise-middleware.js +1 -3
- package/build-module/promise-middleware.js.map +1 -1
- package/build-module/redux-store/index.js +38 -101
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +8 -8
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +1 -21
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +9 -13
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +6 -11
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/redux-store/thunk-middleware.js +0 -1
- package/build-module/redux-store/thunk-middleware.js.map +1 -1
- package/build-module/registry.js +30 -67
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -6
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/select.js +2 -1
- package/build-module/select.js.map +1 -1
- package/build-module/store/index.js +0 -7
- package/build-module/store/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils/emitter.js +2 -10
- package/build-module/utils/emitter.js.map +1 -1
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +2 -2
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/private-apis.d.ts +3 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/index.d.ts +1 -1
- package/build-types/types.d.ts +9 -3
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/use-select/index.js +14 -0
- package/src/dispatch.ts +6 -9
- package/src/plugins/persistence/index.js +0 -1
- package/src/types.ts +38 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -4,27 +4,25 @@
|
|
|
4
4
|
import { createQueue } from '@wordpress/priority-queue';
|
|
5
5
|
import { useRef, useCallback, useMemo, useSyncExternalStore, useDebugValue } from '@wordpress/element';
|
|
6
6
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
import useRegistry from '../registry-provider/use-registry';
|
|
12
12
|
import useAsyncMode from '../async-mode-provider/use-async-mode';
|
|
13
13
|
const renderQueue = createQueue();
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
|
|
16
17
|
* @template {import('../../types').AnyConfig} C
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
/**
|
|
20
20
|
* @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
|
|
21
21
|
* @template State
|
|
22
22
|
* @template {Record<string,import('../../types').ActionCreator>} Actions
|
|
23
23
|
* @template Selectors
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
25
|
/** @typedef {import('../../types').MapSelect} MapSelect */
|
|
27
|
-
|
|
28
26
|
/**
|
|
29
27
|
* @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
|
|
30
28
|
* @template {MapSelect|StoreDescriptor<any>} T
|
|
@@ -38,16 +36,16 @@ function Store(registry, suspense) {
|
|
|
38
36
|
let lastMapResultValid = false;
|
|
39
37
|
let lastIsAsync;
|
|
40
38
|
let subscriber;
|
|
41
|
-
|
|
39
|
+
let didWarnUnstableReference;
|
|
42
40
|
const createSubscriber = stores => {
|
|
43
41
|
// The set of stores the `subscribe` function is supposed to subscribe to. Here it is
|
|
44
42
|
// initialized, and then the `updateStores` function can add new stores to it.
|
|
45
|
-
const activeStores = [...stores];
|
|
43
|
+
const activeStores = [...stores];
|
|
44
|
+
|
|
45
|
+
// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could
|
|
46
46
|
// be called multiple times to establish multiple subscriptions. That's why we need to
|
|
47
47
|
// keep a set of active subscriptions;
|
|
48
|
-
|
|
49
48
|
const activeSubscriptions = new Set();
|
|
50
|
-
|
|
51
49
|
function subscribe(listener) {
|
|
52
50
|
// Invalidate the value right after subscription was created. React will
|
|
53
51
|
// call `getValue` after subscribing, to detect store updates that happened
|
|
@@ -55,13 +53,11 @@ function Store(registry, suspense) {
|
|
|
55
53
|
// the subscription, which is slightly delayed. We need to ensure that this
|
|
56
54
|
// second `getValue` call will compute a fresh value.
|
|
57
55
|
lastMapResultValid = false;
|
|
58
|
-
|
|
59
56
|
const onStoreChange = () => {
|
|
60
57
|
// Invalidate the value on store update, so that a fresh value is computed.
|
|
61
58
|
lastMapResultValid = false;
|
|
62
59
|
listener();
|
|
63
60
|
};
|
|
64
|
-
|
|
65
61
|
const onChange = () => {
|
|
66
62
|
if (lastIsAsync) {
|
|
67
63
|
renderQueue.add(queueContext, onStoreChange);
|
|
@@ -69,53 +65,46 @@ function Store(registry, suspense) {
|
|
|
69
65
|
onStoreChange();
|
|
70
66
|
}
|
|
71
67
|
};
|
|
72
|
-
|
|
73
68
|
const unsubs = [];
|
|
74
|
-
|
|
75
69
|
function subscribeStore(storeName) {
|
|
76
70
|
unsubs.push(registry.subscribe(onChange, storeName));
|
|
77
71
|
}
|
|
78
|
-
|
|
79
72
|
for (const storeName of activeStores) {
|
|
80
73
|
subscribeStore(storeName);
|
|
81
74
|
}
|
|
82
|
-
|
|
83
75
|
activeSubscriptions.add(subscribeStore);
|
|
84
76
|
return () => {
|
|
85
77
|
activeSubscriptions.delete(subscribeStore);
|
|
86
|
-
|
|
87
78
|
for (const unsub of unsubs.values()) {
|
|
88
79
|
// The return value of the subscribe function could be undefined if the store is a custom generic store.
|
|
89
80
|
unsub?.();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
}
|
|
82
|
+
// Cancel existing store updates that were already scheduled.
|
|
93
83
|
renderQueue.cancel(queueContext);
|
|
94
84
|
};
|
|
95
|
-
}
|
|
96
|
-
|
|
85
|
+
}
|
|
97
86
|
|
|
87
|
+
// Check if `newStores` contains some stores we're not subscribed to yet, and add them.
|
|
98
88
|
function updateStores(newStores) {
|
|
99
89
|
for (const newStore of newStores) {
|
|
100
90
|
if (activeStores.includes(newStore)) {
|
|
101
91
|
continue;
|
|
102
|
-
}
|
|
103
|
-
|
|
92
|
+
}
|
|
104
93
|
|
|
105
|
-
|
|
94
|
+
// New `subscribe` calls will subscribe to `newStore`, too.
|
|
95
|
+
activeStores.push(newStore);
|
|
106
96
|
|
|
97
|
+
// Add `newStore` to existing subscriptions.
|
|
107
98
|
for (const subscription of activeSubscriptions) {
|
|
108
99
|
subscription(newStore);
|
|
109
100
|
}
|
|
110
101
|
}
|
|
111
102
|
}
|
|
112
|
-
|
|
113
103
|
return {
|
|
114
104
|
subscribe,
|
|
115
105
|
updateStores
|
|
116
106
|
};
|
|
117
107
|
};
|
|
118
|
-
|
|
119
108
|
return (mapSelect, isAsync) => {
|
|
120
109
|
function updateValue() {
|
|
121
110
|
// If the last value is valid, and the `mapSelect` callback hasn't changed,
|
|
@@ -124,57 +113,60 @@ function Store(registry, suspense) {
|
|
|
124
113
|
if (lastMapResultValid && mapSelect === lastMapSelect) {
|
|
125
114
|
return lastMapResult;
|
|
126
115
|
}
|
|
127
|
-
|
|
128
116
|
const listeningStores = {
|
|
129
117
|
current: null
|
|
130
118
|
};
|
|
131
|
-
|
|
132
119
|
const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores);
|
|
133
|
-
|
|
120
|
+
if (process.env.NODE_ENV === 'development') {
|
|
121
|
+
if (!didWarnUnstableReference) {
|
|
122
|
+
const secondMapResult = mapSelect(select, registry);
|
|
123
|
+
if (!isShallowEqual(mapResult, secondMapResult)) {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.warn(`The 'useSelect' hook returns different values when called with the same state and parameters. This can lead to unnecessary rerenders.`);
|
|
126
|
+
didWarnUnstableReference = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
134
130
|
if (!subscriber) {
|
|
135
131
|
subscriber = createSubscriber(listeningStores.current);
|
|
136
132
|
} else {
|
|
137
133
|
subscriber.updateStores(listeningStores.current);
|
|
138
|
-
}
|
|
139
|
-
// that we don't trigger unwanted updates that do a `===` check.
|
|
140
|
-
|
|
134
|
+
}
|
|
141
135
|
|
|
136
|
+
// If the new value is shallow-equal to the old one, keep the old one so
|
|
137
|
+
// that we don't trigger unwanted updates that do a `===` check.
|
|
142
138
|
if (!isShallowEqual(lastMapResult, mapResult)) {
|
|
143
139
|
lastMapResult = mapResult;
|
|
144
140
|
}
|
|
145
|
-
|
|
146
141
|
lastMapSelect = mapSelect;
|
|
147
142
|
lastMapResultValid = true;
|
|
148
143
|
}
|
|
149
|
-
|
|
150
144
|
function getValue() {
|
|
151
145
|
// Update the value in case it's been invalidated or `mapSelect` has changed.
|
|
152
146
|
updateValue();
|
|
153
147
|
return lastMapResult;
|
|
154
|
-
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// When transitioning from async to sync mode, cancel existing store updates
|
|
155
151
|
// that have been scheduled, and invalidate the value so that it's freshly
|
|
156
152
|
// computed. It might have been changed by the update we just cancelled.
|
|
157
|
-
|
|
158
|
-
|
|
159
153
|
if (lastIsAsync && !isAsync) {
|
|
160
154
|
lastMapResultValid = false;
|
|
161
155
|
renderQueue.cancel(queueContext);
|
|
162
156
|
}
|
|
163
|
-
|
|
164
157
|
updateValue();
|
|
165
|
-
lastIsAsync = isAsync;
|
|
158
|
+
lastIsAsync = isAsync;
|
|
166
159
|
|
|
160
|
+
// Return a pair of functions that can be passed to `useSyncExternalStore`.
|
|
167
161
|
return {
|
|
168
162
|
subscribe: subscriber.subscribe,
|
|
169
163
|
getValue
|
|
170
164
|
};
|
|
171
165
|
};
|
|
172
166
|
}
|
|
173
|
-
|
|
174
167
|
function useStaticSelect(storeName) {
|
|
175
168
|
return useRegistry().select(storeName);
|
|
176
169
|
}
|
|
177
|
-
|
|
178
170
|
function useMappingSelect(suspense, mapSelect, deps) {
|
|
179
171
|
const registry = useRegistry();
|
|
180
172
|
const isAsync = useAsyncMode();
|
|
@@ -188,6 +180,7 @@ function useMappingSelect(suspense, mapSelect, deps) {
|
|
|
188
180
|
useDebugValue(result);
|
|
189
181
|
return result;
|
|
190
182
|
}
|
|
183
|
+
|
|
191
184
|
/**
|
|
192
185
|
* Custom react hook for retrieving props from registered selectors.
|
|
193
186
|
*
|
|
@@ -252,27 +245,24 @@ function useMappingSelect(suspense, mapSelect, deps) {
|
|
|
252
245
|
* ```
|
|
253
246
|
* @return {UseSelectReturn<T>} A custom react hook.
|
|
254
247
|
*/
|
|
255
|
-
|
|
256
|
-
|
|
257
248
|
export default function useSelect(mapSelect, deps) {
|
|
258
249
|
// On initial call, on mount, determine the mode of this `useSelect` call
|
|
259
250
|
// and then never allow it to change on subsequent updates.
|
|
260
251
|
const staticSelectMode = typeof mapSelect !== 'function';
|
|
261
252
|
const staticSelectModeRef = useRef(staticSelectMode);
|
|
262
|
-
|
|
263
253
|
if (staticSelectMode !== staticSelectModeRef.current) {
|
|
264
254
|
const prevMode = staticSelectModeRef.current ? 'static' : 'mapping';
|
|
265
255
|
const nextMode = staticSelectMode ? 'static' : 'mapping';
|
|
266
256
|
throw new Error(`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`);
|
|
267
257
|
}
|
|
258
|
+
|
|
268
259
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
269
260
|
// `staticSelectMode` is not allowed to change during the hook instance's,
|
|
270
261
|
// lifetime, so the rules of hooks are not really violated.
|
|
271
|
-
|
|
272
|
-
|
|
273
262
|
return staticSelectMode ? useStaticSelect(mapSelect) : useMappingSelect(false, mapSelect, deps);
|
|
274
263
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
275
264
|
}
|
|
265
|
+
|
|
276
266
|
/**
|
|
277
267
|
* A variant of the `useSelect` hook that has the same API, but will throw a
|
|
278
268
|
* suspense Promise if any of the called selectors is in an unresolved state.
|
|
@@ -288,7 +278,6 @@ export default function useSelect(mapSelect, deps) {
|
|
|
288
278
|
*
|
|
289
279
|
* @return {Object} Data object returned by the `mapSelect` function.
|
|
290
280
|
*/
|
|
291
|
-
|
|
292
281
|
export function useSuspenseSelect(mapSelect, deps) {
|
|
293
282
|
return useMappingSelect(true, mapSelect, deps);
|
|
294
283
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","createSubscriber","stores","activeStores","activeSubscriptions","Set","subscribe","listener","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","getValue","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,2BAA5B;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,OAHD,EAICC,oBAJD,EAKCC,aALD,QAMO,oBANP;AAOA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AACA,OAAOC,YAAP,MAAyB,uCAAzB;AAEA,MAAMC,WAAW,GAAGT,WAAW,EAA/B;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;AACA;AACA;AACA;;AAEA,SAASU,KAAT,CAAgBC,QAAhB,EAA0BC,QAA1B,EAAqC;AACpC,QAAMC,MAAM,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,aAAZ,GAA4BH,QAAQ,CAACE,MAA5D;AACA,QAAME,YAAY,GAAG,EAArB;AACA,MAAIC,aAAJ;AACA,MAAIC,aAAJ;AACA,MAAIC,kBAAkB,GAAG,KAAzB;AACA,MAAIC,WAAJ;AACA,MAAIC,UAAJ;;AAEA,QAAMC,gBAAgB,GAAKC,MAAF,IAAc;AACtC;AACA;AACA,UAAMC,YAAY,GAAG,CAAE,GAAGD,MAAL,CAArB,CAHsC,CAKtC;AACA;AACA;;AACA,UAAME,mBAAmB,GAAG,IAAIC,GAAJ,EAA5B;;AAEA,aAASC,SAAT,CAAoBC,QAApB,EAA+B;AAC9B;A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AAM,CAAE0D,gBAAF,CAAlC;;AAEA,MAAKA,gBAAgB,KAAKC,mBAAmB,CAACZ,OAA9C,EAAwD;AACvD,UAAMa,QAAQ,GAAGD,mBAAmB,CAACZ,OAApB,GAA8B,QAA9B,GAAyC,SAA1D;AACA,UAAMc,QAAQ,GAAGH,gBAAgB,GAAG,QAAH,GAAc,SAA/C;AACA,UAAM,IAAII,KAAJ,CACJ,4BAA4BF,QAAU,OAAOC,QAAU,iBADnD,CAAN;AAGA;AAED;AACA;AACA;;;AACA,SAAOH,gBAAgB,GACpBP,eAAe,CAAER,SAAF,CADK,GAEpBS,gBAAgB,CAAE,KAAF,EAAST,SAAT,EAAoBU,IAApB,CAFnB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASU,iBAAT,CAA4BpB,SAA5B,EAAuCU,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQT,SAAR,EAAmBU,IAAnB,CAAvB;AACA","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\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\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// Invalidate the value right after subscription was created. React will\n\t\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t\t// in the interval between the `getValue` call during render and creating\n\t\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t\t// second `getValue` call will compute a fresh value.\n\t\t\tlastMapResultValid = false;\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 ( ! subscriber ) {\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( () => Store( registry, suspense ), [ registry ] );\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://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\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/* eslint-disable react-hooks/rules-of-hooks */\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\t/* eslint-enable react-hooks/rules-of-hooks */\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
|
|
1
|
+
{"version":3,"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","didWarnUnstableReference","createSubscriber","stores","activeStores","activeSubscriptions","Set","subscribe","listener","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","process","env","NODE_ENV","secondMapResult","console","warn","getValue","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","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\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\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// Invalidate the value right after subscription was created. React will\n\t\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t\t// in the interval between the `getValue` call during render and creating\n\t\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t\t// second `getValue` call will compute a fresh value.\n\t\t\tlastMapResultValid = false;\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 ( process.env.NODE_ENV === 'development' ) {\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\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`The 'useSelect' hook returns different values when called with the same state and parameters. This can lead to unnecessary rerenders.`\n\t\t\t\t\t\t);\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\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( () => Store( registry, suspense ), [ registry ] );\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://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\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/* eslint-disable react-hooks/rules-of-hooks */\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\t/* eslint-enable react-hooks/rules-of-hooks */\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn useMappingSelect( true, mapSelect, deps );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,2BAA2B;AACvD,SACCC,MAAM,EACNC,WAAW,EACXC,OAAO,EACPC,oBAAoB,EACpBC,aAAa,QACP,oBAAoB;AAC3B,OAAOC,cAAc,MAAM,6BAA6B;;AAExD;AACA;AACA;AACA,OAAOC,WAAW,MAAM,mCAAmC;AAC3D,OAAOC,YAAY,MAAM,uCAAuC;AAEhE,MAAMC,WAAW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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,iBAAiBA,CAAE1B,SAAS,EAAEgB,IAAI,EAAG;EACpD,OAAOD,gBAAgB,CAAE,IAAI,EAAEf,SAAS,EAAEgB,IAAK,CAAC;AACjD"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { useDispatchWithMap } from '../use-dispatch';
|
|
11
|
+
|
|
12
12
|
/** @typedef {import('@wordpress/element').WPComponent} WPComponent */
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -92,15 +92,13 @@ import { useDispatchWithMap } from '../use-dispatch';
|
|
|
92
92
|
*
|
|
93
93
|
* @return {WPComponent} Enhanced component with merged dispatcher props.
|
|
94
94
|
*/
|
|
95
|
-
|
|
96
95
|
const withDispatch = mapDispatchToProps => createHigherOrderComponent(WrappedComponent => ownProps => {
|
|
97
96
|
const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
|
|
98
|
-
|
|
99
97
|
const dispatchProps = useDispatchWithMap(mapDispatch, []);
|
|
100
|
-
return createElement(WrappedComponent, {
|
|
98
|
+
return createElement(WrappedComponent, {
|
|
99
|
+
...ownProps,
|
|
101
100
|
...dispatchProps
|
|
102
101
|
});
|
|
103
102
|
}, 'withDispatch');
|
|
104
|
-
|
|
105
103
|
export default withDispatch;
|
|
106
104
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createHigherOrderComponent","useDispatchWithMap","withDispatch","mapDispatchToProps","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps","createElement"],"sources":["@wordpress/data/src/components/with-dispatch/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/** @typedef {import('@wordpress/element').WPComponent} WPComponent */\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {WPComponent} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,0BAA0B,QAAQ,oBAAoB;;AAE/D;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,iBAAiB;;AAEpD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAKC,kBAAkB,IACxCH,0BAA0B,CACvBI,gBAAgB,IAAQC,QAAQ,IAAM;EACvC,MAAMC,WAAW,GAAGA,CAAEC,QAAQ,EAAEC,QAAQ,KACvCL,kBAAkB,CAAEI,QAAQ,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EACnD,MAAMC,aAAa,GAAGR,kBAAkB,CAAEK,WAAW,EAAE,EAAG,CAAC;EAC3D,OAAOI,aAAA,CAACN,gBAAgB;IAAA,GAAMC,QAAQ;IAAA,GAAQI;EAAa,CAAI,CAAC;AACjE,CAAC,EACD,cACD,CAAC;AAEF,eAAeP,YAAY"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { RegistryConsumer } from '../registry-provider';
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Higher-order component which renders the original component with the current
|
|
14
14
|
* registry context passed as its `registry` prop.
|
|
@@ -17,8 +17,8 @@ import { RegistryConsumer } from '../registry-provider';
|
|
|
17
17
|
*
|
|
18
18
|
* @return {WPComponent} Enhanced component.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const withRegistry = createHigherOrderComponent(OriginalComponent => props => createElement(RegistryConsumer, null, registry => createElement(OriginalComponent, {
|
|
21
|
+
...props,
|
|
22
22
|
registry: registry
|
|
23
23
|
})), 'withRegistry');
|
|
24
24
|
export default withRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createHigherOrderComponent","RegistryConsumer","withRegistry","OriginalComponent","props","createElement","registry"],"sources":["@wordpress/data/src/components/with-registry/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {WPComponent} OriginalComponent Original component.\n *\n * @return {WPComponent} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) =>\n\t\t(\n\t\t\t<RegistryConsumer>\n\t\t\t\t{ ( registry ) => (\n\t\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t\t) }\n\t\t\t</RegistryConsumer>\n\t\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,0BAA0B,QAAQ,oBAAoB;;AAE/D;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,sBAAsB;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGF,0BAA0B,CAC5CG,iBAAiB,IAAQC,KAAK,IAE9BC,aAAA,CAACJ,gBAAgB,QACZK,QAAQ,IACXD,aAAA,CAACF,iBAAiB;EAAA,GAAMC,KAAK;EAAGE,QAAQ,EAAGA;AAAU,CAAE,CAEvC,CAClB,EACF,cACD,CAAC;AAED,eAAeJ,YAAY"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { createHigherOrderComponent, pure } from '@wordpress/compose';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import useSelect from '../use-select';
|
|
11
|
+
|
|
12
12
|
/** @typedef {import('@wordpress/element').WPComponent} WPComponent */
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -51,15 +51,13 @@ import useSelect from '../use-select';
|
|
|
51
51
|
*
|
|
52
52
|
* @return {WPComponent} Enhanced component with merged state data props.
|
|
53
53
|
*/
|
|
54
|
-
|
|
55
54
|
const withSelect = mapSelectToProps => createHigherOrderComponent(WrappedComponent => pure(ownProps => {
|
|
56
55
|
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
57
|
-
|
|
58
56
|
const mergeProps = useSelect(mapSelect);
|
|
59
|
-
return createElement(WrappedComponent, {
|
|
57
|
+
return createElement(WrappedComponent, {
|
|
58
|
+
...ownProps,
|
|
60
59
|
...mergeProps
|
|
61
60
|
});
|
|
62
61
|
}), 'withSelect');
|
|
63
|
-
|
|
64
62
|
export default withSelect;
|
|
65
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createHigherOrderComponent","pure","useSelect","withSelect","mapSelectToProps","WrappedComponent","ownProps","mapSelect","select","registry","mergeProps","createElement"],"sources":["@wordpress/data/src/components/with-select/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('@wordpress/element').WPComponent} WPComponent */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {WPComponent} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,0BAA0B,EAAEC,IAAI,QAAQ,oBAAoB;;AAErE;AACA;AACA;AACA,OAAOC,SAAS,MAAM,eAAe;;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAKC,gBAAgB,IACpCJ,0BAA0B,CACvBK,gBAAgB,IACjBJ,IAAI,CAAIK,QAAQ,IAAM;EACrB,MAAMC,SAAS,GAAGA,CAAEC,MAAM,EAAEC,QAAQ,KACnCL,gBAAgB,CAAEI,MAAM,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EAC/C,MAAMC,UAAU,GAAGR,SAAS,CAAEK,SAAU,CAAC;EACzC,OAAOI,aAAA,CAACN,gBAAgB;IAAA,GAAMC,QAAQ;IAAA,GAAQI;EAAU,CAAI,CAAC;AAC9D,CAAE,CAAC,EACJ,YACD,CAAC;AAEF,eAAeP,UAAU"}
|
package/build-module/controls.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createRegistryControl } from './factory';
|
|
5
|
+
|
|
5
6
|
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
6
7
|
|
|
7
8
|
const SELECT = '@@data/SELECT';
|
|
8
9
|
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
|
|
9
10
|
const DISPATCH = '@@data/DISPATCH';
|
|
10
|
-
|
|
11
11
|
function isObject(object) {
|
|
12
12
|
return object !== null && typeof object === 'object';
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* Dispatches a control action for triggering a synchronous registry select.
|
|
16
17
|
*
|
|
@@ -34,8 +35,6 @@ function isObject(object) {
|
|
|
34
35
|
*
|
|
35
36
|
* @return {Object} The control descriptor.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
38
|
function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
40
39
|
return {
|
|
41
40
|
type: SELECT,
|
|
@@ -44,6 +43,7 @@ function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
44
43
|
args
|
|
45
44
|
};
|
|
46
45
|
}
|
|
46
|
+
|
|
47
47
|
/**
|
|
48
48
|
* Dispatches a control action for triggering and resolving a registry select.
|
|
49
49
|
*
|
|
@@ -68,8 +68,6 @@ function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
68
68
|
*
|
|
69
69
|
* @return {Object} The control descriptor.
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
71
|
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
74
72
|
return {
|
|
75
73
|
type: RESOLVE_SELECT,
|
|
@@ -78,6 +76,7 @@ function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
78
76
|
args
|
|
79
77
|
};
|
|
80
78
|
}
|
|
79
|
+
|
|
81
80
|
/**
|
|
82
81
|
* Dispatches a control action for triggering a registry dispatch.
|
|
83
82
|
*
|
|
@@ -98,8 +97,6 @@ function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
98
97
|
*
|
|
99
98
|
* @return {Object} The control descriptor.
|
|
100
99
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
100
|
function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
104
101
|
return {
|
|
105
102
|
type: DISPATCH,
|
|
@@ -108,7 +105,6 @@ function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
|
108
105
|
args
|
|
109
106
|
};
|
|
110
107
|
}
|
|
111
|
-
|
|
112
108
|
export const controls = {
|
|
113
109
|
select,
|
|
114
110
|
resolveSelect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createRegistryControl","SELECT","RESOLVE_SELECT","DISPATCH","isObject","object","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"sources":["@wordpress/data/src/controls.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isObject( object ) {\n\treturn object !== null && typeof object === 'object';\n}\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,qBAAqB,QAAQ,WAAW;;AAEjD;;AAEA,MAAMC,MAAM,GAAG,eAAe;AAC9B,MAAMC,cAAc,GAAG,uBAAuB;AAC9C,MAAMC,QAAQ,GAAG,iBAAiB;AAElC,SAASC,QAAQA,CAAEC,MAAM,EAAG;EAC3B,OAAOA,MAAM,KAAK,IAAI,IAAI,OAAOA,MAAM,KAAK,QAAQ;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,MAAMA,CAAEC,qBAAqB,EAAEC,YAAY,EAAE,GAAGC,IAAI,EAAG;EAC/D,OAAO;IACNC,IAAI,EAAET,MAAM;IACZU,QAAQ,EAAEP,QAAQ,CAAEG,qBAAsB,CAAC,GACxCA,qBAAqB,CAACK,IAAI,GAC1BL,qBAAqB;IACxBC,YAAY;IACZC;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;A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,CAAEC,MAAM,CAAE,CAAER,QAAS,CAAC,CAAEH,YAAY,CAAE,CACpD,GAAGC,IACJ,CAAC;EACF,CACF,CAAC;EACD,CAAEN,QAAQ,GAAIH,qBAAqB,CAChCkB,QAAQ,IACT,CAAE;IAAEP,QAAQ;IAAEI,UAAU;IAAEN;EAAK,CAAC,KAC/BS,QAAQ,CAACJ,QAAQ,CAAEH,QAAS,CAAC,CAAEI,UAAU,CAAE,CAAE,GAAGN,IAAK,CACxD;AACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/default-registry.js"],"
|
|
1
|
+
{"version":3,"names":["createRegistry"],"sources":["@wordpress/data/src/default-registry.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createRegistry } from './registry';\n\nexport default createRegistry();\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,YAAY;AAE3C,eAAeA,cAAc,CAAC,CAAC"}
|
package/build-module/dispatch.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import defaultRegistry from './default-registry';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Given a store descriptor, returns an object of the store's action creators.
|
|
7
9
|
* Calling an action creator will cause it to be dispatched, updating the state value accordingly.
|
|
@@ -21,7 +23,6 @@ import defaultRegistry from './default-registry';
|
|
|
21
23
|
* ```
|
|
22
24
|
* @return Object containing the action creators.
|
|
23
25
|
*/
|
|
24
|
-
|
|
25
26
|
export function dispatch(storeNameOrDescriptor) {
|
|
26
27
|
return defaultRegistry.dispatch(storeNameOrDescriptor);
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["defaultRegistry","dispatch","storeNameOrDescriptor"],"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":"AAAA;AACA;AACA;;AAEA,OAAOA,eAAe,MAAM,oBAAoB;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAGvBC,qBAA4C,EACF;EAC1C,OAAOF,eAAe,CAACC,QAAQ,CAAEC,qBAAsB,CAAC;AACzD"}
|