@wordpress/data 6.1.3 → 6.2.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 +12 -0
- package/LICENSE.md +1 -1
- package/README.md +68 -68
- package/build/components/async-mode-provider/context.js +1 -1
- package/build/components/async-mode-provider/index.js +8 -6
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/registry-provider/index.js +8 -6
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +3 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +8 -8
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +58 -43
- package/build/components/use-select/index.js.map +1 -1
- package/build/controls.js +51 -32
- package/build/controls.js.map +1 -1
- package/build/factory.js +4 -2
- package/build/factory.js.map +1 -1
- package/build/index.js +49 -47
- package/build/index.js.map +1 -1
- package/build/plugins/persistence/index.js +2 -1
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +62 -34
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +2 -2
- package/build/redux-store/metadata/reducer.js +8 -2
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +8 -5
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +5 -5
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +81 -66
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +7 -4
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js +42 -35
- package/build/store/index.js.map +1 -1
- package/build/types.js +4 -0
- package/build/utils/emitter.js +1 -1
- package/build/utils/emitter.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +3 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -8
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +60 -44
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/controls.js +50 -31
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +3 -1
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +14 -14
- package/build-module/index.js.map +1 -1
- package/build-module/redux-store/index.js +58 -32
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +8 -2
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +6 -3
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +5 -5
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +81 -66
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +5 -4
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js +42 -34
- package/build-module/store/index.js.map +1 -1
- package/build-module/types.js +1 -1
- package/build-module/utils/emitter.js +1 -1
- package/build-module/utils/emitter.js.map +1 -1
- package/build-types/types.d.ts +29 -16
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/emitter.d.ts +2 -2
- package/build-types/utils/emitter.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/components/use-dispatch/test/use-dispatch.js +1 -1
- package/src/components/use-dispatch/use-dispatch.js +9 -9
- package/src/components/use-select/index.js +61 -46
- package/src/components/use-select/test/index.js +32 -32
- package/src/controls.js +22 -22
- package/src/index.js +14 -14
- package/src/redux-store/index.js +15 -15
- package/src/registry.js +84 -75
- package/src/resolvers-cache-middleware.js +3 -3
- package/src/store/index.js +49 -48
- package/src/test/registry.js +33 -47
- package/src/types.ts +44 -16
- package/src/utils/emitter.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/store/name.js +0 -15
- package/build/store/name.js.map +0 -1
- package/build-module/store/name.js +0 -7
- package/build-module/store/name.js.map +0 -1
- package/src/store/name.js +0 -6
package/build/registry.js
CHANGED
|
@@ -9,23 +9,27 @@ exports.createRegistry = createRegistry;
|
|
|
9
9
|
|
|
10
10
|
var _lodash = require("lodash");
|
|
11
11
|
|
|
12
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
13
|
+
|
|
12
14
|
var _reduxStore = _interopRequireDefault(require("./redux-store"));
|
|
13
15
|
|
|
14
16
|
var _store = _interopRequireDefault(require("./store"));
|
|
15
17
|
|
|
16
|
-
var _name = require("./store/name");
|
|
17
|
-
|
|
18
18
|
var _emitter = require("./utils/emitter");
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* External dependencies
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* WordPress dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* Internal dependencies
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
|
-
/** @typedef {import('./types').
|
|
32
|
+
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.
|
|
@@ -62,7 +66,9 @@ var _emitter = require("./utils/emitter");
|
|
|
62
66
|
*
|
|
63
67
|
* @return {WPDataRegistry} Data registry.
|
|
64
68
|
*/
|
|
65
|
-
function createRegistry(
|
|
69
|
+
function createRegistry() {
|
|
70
|
+
let storeConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
66
72
|
const stores = {};
|
|
67
73
|
const emitter = (0, _emitter.createEmitter)();
|
|
68
74
|
|
|
@@ -90,15 +96,15 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
90
96
|
/**
|
|
91
97
|
* Calls a selector given the current state and extra arguments.
|
|
92
98
|
*
|
|
93
|
-
* @param {string|
|
|
94
|
-
*
|
|
99
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
100
|
+
* or the store descriptor.
|
|
95
101
|
*
|
|
96
102
|
* @return {*} The selector's returned value.
|
|
97
103
|
*/
|
|
98
104
|
|
|
99
105
|
|
|
100
|
-
function select(
|
|
101
|
-
const storeName = (0, _lodash.isObject)(
|
|
106
|
+
function select(storeNameOrDescriptor) {
|
|
107
|
+
const storeName = (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
|
|
102
108
|
|
|
103
109
|
__experimentalListeningStores.add(storeName);
|
|
104
110
|
|
|
@@ -124,15 +130,15 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
124
130
|
* and modified so that they return promises that resolve to their eventual values,
|
|
125
131
|
* after any resolvers have ran.
|
|
126
132
|
*
|
|
127
|
-
* @param {string|
|
|
128
|
-
*
|
|
133
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
134
|
+
* or the store descriptor.
|
|
129
135
|
*
|
|
130
136
|
* @return {Object} Each key of the object matches the name of a selector.
|
|
131
137
|
*/
|
|
132
138
|
|
|
133
139
|
|
|
134
|
-
function resolveSelect(
|
|
135
|
-
const storeName = (0, _lodash.isObject)(
|
|
140
|
+
function resolveSelect(storeNameOrDescriptor) {
|
|
141
|
+
const storeName = (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
|
|
136
142
|
|
|
137
143
|
__experimentalListeningStores.add(storeName);
|
|
138
144
|
|
|
@@ -147,15 +153,15 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
147
153
|
/**
|
|
148
154
|
* Returns the available actions for a part of the state.
|
|
149
155
|
*
|
|
150
|
-
* @param {string|
|
|
151
|
-
*
|
|
156
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
157
|
+
* or the store descriptor.
|
|
152
158
|
*
|
|
153
159
|
* @return {*} The action's returned value.
|
|
154
160
|
*/
|
|
155
161
|
|
|
156
162
|
|
|
157
|
-
function dispatch(
|
|
158
|
-
const storeName = (0, _lodash.isObject)(
|
|
163
|
+
function dispatch(storeNameOrDescriptor) {
|
|
164
|
+
const storeName = (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
|
|
159
165
|
const store = stores[storeName];
|
|
160
166
|
|
|
161
167
|
if (store) {
|
|
@@ -181,63 +187,87 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
181
187
|
});
|
|
182
188
|
}
|
|
183
189
|
/**
|
|
184
|
-
* Registers a
|
|
190
|
+
* Registers a store instance.
|
|
185
191
|
*
|
|
186
|
-
* @param {string}
|
|
187
|
-
* @param {Object}
|
|
192
|
+
* @param {string} name Store registry name.
|
|
193
|
+
* @param {Object} store Store instance object (getSelectors, getActions, subscribe).
|
|
188
194
|
*/
|
|
189
195
|
|
|
190
196
|
|
|
191
|
-
function
|
|
192
|
-
if (typeof
|
|
193
|
-
throw new TypeError('
|
|
197
|
+
function registerStoreInstance(name, store) {
|
|
198
|
+
if (typeof store.getSelectors !== 'function') {
|
|
199
|
+
throw new TypeError('store.getSelectors must be a function');
|
|
194
200
|
}
|
|
195
201
|
|
|
196
|
-
if (typeof
|
|
197
|
-
throw new TypeError('
|
|
202
|
+
if (typeof store.getActions !== 'function') {
|
|
203
|
+
throw new TypeError('store.getActions must be a function');
|
|
198
204
|
}
|
|
199
205
|
|
|
200
|
-
if (typeof
|
|
201
|
-
throw new TypeError('
|
|
202
|
-
} //
|
|
206
|
+
if (typeof store.subscribe !== 'function') {
|
|
207
|
+
throw new TypeError('store.subscribe must be a function');
|
|
208
|
+
} // The emitter is used to keep track of active listeners when the registry
|
|
203
209
|
// get paused, that way, when resumed we should be able to call all these
|
|
204
210
|
// pending listeners.
|
|
205
211
|
|
|
206
212
|
|
|
207
|
-
|
|
208
|
-
const currentSubscribe =
|
|
213
|
+
store.emitter = (0, _emitter.createEmitter)();
|
|
214
|
+
const currentSubscribe = store.subscribe;
|
|
209
215
|
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
214
|
-
|
|
216
|
+
store.subscribe = listener => {
|
|
217
|
+
const unsubscribeFromEmitter = store.emitter.subscribe(listener);
|
|
218
|
+
const unsubscribeFromStore = currentSubscribe(() => {
|
|
219
|
+
if (store.emitter.isPaused) {
|
|
220
|
+
store.emitter.emit();
|
|
215
221
|
return;
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
listener();
|
|
219
225
|
});
|
|
220
226
|
return () => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
unsubscribeFromStoreEmitter();
|
|
227
|
+
unsubscribeFromStore === null || unsubscribeFromStore === void 0 ? void 0 : unsubscribeFromStore();
|
|
228
|
+
unsubscribeFromEmitter === null || unsubscribeFromEmitter === void 0 ? void 0 : unsubscribeFromEmitter();
|
|
226
229
|
};
|
|
227
230
|
};
|
|
228
231
|
|
|
229
|
-
stores[
|
|
230
|
-
|
|
232
|
+
stores[name] = store;
|
|
233
|
+
store.subscribe(globalListener);
|
|
231
234
|
}
|
|
232
235
|
/**
|
|
233
|
-
* Registers a new store
|
|
236
|
+
* Registers a new store given a store descriptor.
|
|
234
237
|
*
|
|
235
|
-
* @param {
|
|
238
|
+
* @param {StoreDescriptor} store Store descriptor.
|
|
236
239
|
*/
|
|
237
240
|
|
|
238
241
|
|
|
239
242
|
function register(store) {
|
|
240
|
-
|
|
243
|
+
registerStoreInstance(store.name, store.instantiate(registry));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function registerGenericStore(name, store) {
|
|
247
|
+
(0, _deprecated.default)('wp.data.registerGenericStore', {
|
|
248
|
+
since: '5.9',
|
|
249
|
+
alternative: 'wp.data.register( storeDescriptor )'
|
|
250
|
+
});
|
|
251
|
+
registerStoreInstance(name, store);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Registers a standard `@wordpress/data` store.
|
|
255
|
+
*
|
|
256
|
+
* @param {string} storeName Unique namespace identifier.
|
|
257
|
+
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
258
|
+
*
|
|
259
|
+
* @return {Object} Registered store object.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
function registerStore(storeName, options) {
|
|
264
|
+
if (!options.reducer) {
|
|
265
|
+
throw new TypeError('Must specify store reducer');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const store = (0, _reduxStore.default)(storeName, options).instantiate(registry);
|
|
269
|
+
registerStoreInstance(storeName, store);
|
|
270
|
+
return store.store;
|
|
241
271
|
}
|
|
242
272
|
/**
|
|
243
273
|
* Subscribe handler to a store.
|
|
@@ -274,7 +304,6 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
274
304
|
|
|
275
305
|
let registry = {
|
|
276
306
|
batch,
|
|
277
|
-
registerGenericStore,
|
|
278
307
|
stores,
|
|
279
308
|
namespaces: stores,
|
|
280
309
|
// TODO: Deprecate/remove this.
|
|
@@ -284,32 +313,15 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
284
313
|
dispatch,
|
|
285
314
|
use,
|
|
286
315
|
register,
|
|
316
|
+
registerGenericStore,
|
|
317
|
+
registerStore,
|
|
287
318
|
__experimentalMarkListeningStores,
|
|
288
319
|
__experimentalSubscribeStore
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Registers a standard `@wordpress/data` store.
|
|
292
|
-
*
|
|
293
|
-
* @param {string} storeName Unique namespace identifier.
|
|
294
|
-
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
295
|
-
*
|
|
296
|
-
* @return {Object} Registered store object.
|
|
297
|
-
*/
|
|
298
|
-
|
|
299
|
-
registry.registerStore = (storeName, options) => {
|
|
300
|
-
if (!options.reducer) {
|
|
301
|
-
throw new TypeError('Must specify store reducer');
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const store = (0, _reduxStore.default)(storeName, options).instantiate(registry);
|
|
305
|
-
registerGenericStore(storeName, store);
|
|
306
|
-
return store.store;
|
|
307
320
|
}; //
|
|
308
321
|
// TODO:
|
|
309
322
|
// This function will be deprecated as soon as it is no longer internally referenced.
|
|
310
323
|
//
|
|
311
324
|
|
|
312
|
-
|
|
313
325
|
function use(plugin, options) {
|
|
314
326
|
registry = { ...registry,
|
|
315
327
|
...plugin(registry, options)
|
|
@@ -317,8 +329,11 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
317
329
|
return registry;
|
|
318
330
|
}
|
|
319
331
|
|
|
320
|
-
|
|
321
|
-
|
|
332
|
+
registry.register(_store.default);
|
|
333
|
+
|
|
334
|
+
for (const [name, config] of Object.entries(storeConfigs)) {
|
|
335
|
+
registry.register((0, _reduxStore.default)(name, config));
|
|
336
|
+
}
|
|
322
337
|
|
|
323
338
|
if (parent) {
|
|
324
339
|
parent.subscribe(globalListener);
|
package/build/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","__experimentalListeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDefinition","storeName","name","add","store","getSelectors","__experimentalMarkListeningStores","callback","ref","clear","result","call","current","Array","from","resolveSelect","getResolveSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerGenericStore","config","TypeError","currentSubscribe","unsubscribeFromStoreEmitter","unsubscribeFromRootStore","isPaused","register","instantiate","__experimentalSubscribeStore","handler","batch","pause","resume","namespaces","use","registerStore","options","reducer","plugin","STORE_NAME","Object","entries","forEach"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;;AAEA;A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xB,KAAK,GAAG,yBAAkBH,SAAlB,EAA6B0C,OAA7B,EAAuCT,WAAvC,CACbX,QADa,CAAd;AAGAG,IAAAA,oBAAoB,CAAEzB,SAAF,EAAaG,KAAb,CAApB;AACA,WAAOA,KAAK,CAACA,KAAb;AACA,GAVD,CAzNkE,CAqOlE;AACA;AACA;AACA;;;AACA,WAASqC,GAAT,CAAcI,MAAd,EAAsBF,OAAtB,EAAgC;AAC/BpB,IAAAA,QAAQ,GAAG,EACV,GAAGA,QADO;AAEV,SAAGsB,MAAM,CAAEtB,QAAF,EAAYoB,OAAZ;AAFC,KAAX;AAKA,WAAOpB,QAAP;AACA;;AAEDG,EAAAA,oBAAoB,CAAEoB,gBAAF,EAAc,oBAAqBvB,QAArB,CAAd,CAApB;AAEAwB,EAAAA,MAAM,CAACC,OAAP,CAAgB3D,YAAhB,EAA+B4D,OAA/B,CAAwC,CAAE,CAAE/C,IAAF,EAAQyB,MAAR,CAAF,KACvCJ,QAAQ,CAACmB,aAAT,CAAwBxC,IAAxB,EAA8ByB,MAA9B,CADD;;AAIA,MAAKrC,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACO,SAAP,CAAkBF,cAAlB;AACA;;AAED,SAAOwB,WAAW,CAAEI,QAAF,CAAlB;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues, isObject, forEach } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport createCoreDataStore from './store';\nimport { STORE_NAME } from './store/name';\nimport { createEmitter } from './utils/emitter';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tconst __experimentalListeningStores = new Set();\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n\t * or the store definition.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDefinition ) {\n\t\tconst storeName = isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent && parent.select( storeName );\n\t}\n\n\tfunction __experimentalMarkListeningStores( callback, ref ) {\n\t\t__experimentalListeningStores.clear();\n\t\tconst result = callback.call( this );\n\t\tref.current = Array.from( __experimentalListeningStores );\n\t\treturn result;\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\n\t *\n\t * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n\t * or the store definition.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDefinition ) {\n\t\tconst storeName = isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n\t * or the store definition.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDefinition ) {\n\t\tconst storeName = isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition;\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\t//\n\tfunction withPlugins( attributes ) {\n\t\treturn mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t};\n\t\t} );\n\t}\n\n\t/**\n\t * Registers a generic store.\n\t *\n\t * @param {string} key Store registry key.\n\t * @param {Object} config Configuration (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerGenericStore( key, config ) {\n\t\tif ( typeof config.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'config.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof config.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'config.getActions must be a function' );\n\t\t}\n\t\tif ( typeof config.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'config.subscribe must be a function' );\n\t\t}\n\t\t// Thi emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tconfig.emitter = createEmitter();\n\t\tconst currentSubscribe = config.subscribe;\n\t\tconfig.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromStoreEmitter = config.emitter.subscribe(\n\t\t\t\tlistener\n\t\t\t);\n\t\t\tconst unsubscribeFromRootStore = currentSubscribe( () => {\n\t\t\t\tif ( config.emitter.isPaused ) {\n\t\t\t\t\tconfig.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( unsubscribeFromRootStore ) {\n\t\t\t\t\tunsubscribeFromRootStore();\n\t\t\t\t}\n\t\t\t\tunsubscribeFromStoreEmitter();\n\t\t\t};\n\t\t};\n\t\tstores[ key ] = config;\n\t\tconfig.subscribe( globalListener );\n\t}\n\n\t/**\n\t * Registers a new store definition.\n\t *\n\t * @param {WPDataStore} store Store definition.\n\t */\n\tfunction register( store ) {\n\t\tregisterGenericStore( store.name, store.instantiate( registry ) );\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __experimentalSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to regular `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn subscribe( handler );\n\t\t}\n\n\t\treturn parent.__experimentalSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tregisterGenericStore,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\t__experimentalMarkListeningStores,\n\t\t__experimentalSubscribeStore,\n\t};\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tregistry.registerStore = ( storeName, options ) => {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterGenericStore( storeName, store );\n\t\treturn store.store;\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\t//\n\tfunction use( plugin, options ) {\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregisterGenericStore( STORE_NAME, createCoreDataStore( registry ) );\n\n\tObject.entries( storeConfigs ).forEach( ( [ name, config ] ) =>\n\t\tregistry.registerStore( name, config )\n\t);\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\treturn withPlugins( registry );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","__experimentalListeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDescriptor","storeName","name","add","store","getSelectors","__experimentalMarkListeningStores","callback","ref","clear","result","call","current","Array","from","resolveSelect","getResolveSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerStoreInstance","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","__experimentalSubscribeStore","handler","batch","pause","resume","namespaces","use","plugin","coreDataStore","config","Object","entries"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,GAA4D;AAAA,MAAnCC,YAAmC,uEAApB,EAAoB;AAAA,MAAhBC,MAAgB,uEAAP,IAAO;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAG,6BAAhB;;AACA,QAAMC,6BAA6B,GAAG,IAAIC,GAAJ,EAAtC;AAEA;AACD;AACA;;;AACC,WAASC,cAAT,GAA0B;AACzBH,IAAAA,OAAO,CAACI,IAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMC,SAAS,GAAKC,QAAF,IAAgB;AACjC,WAAON,OAAO,CAACK,SAAR,CAAmBC,QAAnB,CAAP;AACA,GAFD;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,WAASC,MAAT,CAAiBC,qBAAjB,EAAyC;AACxC,UAAMC,SAAS,GAAG,sBAAUD,qBAAV,IACfA,qBAAqB,CAACE,IADP,GAEfF,qBAFH;;AAGAP,IAAAA,6BAA6B,CAACU,GAA9B,CAAmCF,SAAnC;;AACA,UAAMG,KAAK,GAAGb,MAAM,CAAEU,SAAF,CAApB;;AACA,QAAKG,KAAL,EAAa;AACZ,aAAOA,KAAK,CAACC,YAAN,EAAP;AACA;;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+C,MAAxB,CAAnB;AACA;;AAED,MAAK3D,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACO,SAAP,CAAkBF,cAAlB;AACA;;AAED,SAAOwB,WAAW,CAAEI,QAAF,CAAlB;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues, isObject, forEach } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tconst __experimentalListeningStores = new Set();\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent && parent.select( storeName );\n\t}\n\n\tfunction __experimentalMarkListeningStores( callback, ref ) {\n\t\t__experimentalListeningStores.clear();\n\t\tconst result = callback.call( this );\n\t\tref.current = Array.from( __experimentalListeningStores );\n\t\treturn result;\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\t//\n\tfunction withPlugins( attributes ) {\n\t\treturn mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t};\n\t\t} );\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Object} store Store instance object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, store ) {\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, store.instantiate( registry ) );\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterStoreInstance( storeName, store );\n\t\treturn store.store;\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __experimentalSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to regular `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn subscribe( handler );\n\t\t}\n\n\t\treturn parent.__experimentalSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__experimentalMarkListeningStores,\n\t\t__experimentalSubscribeStore,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\t//\n\tfunction use( plugin, options ) {\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\treturn withPlugins( registry );\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -7,7 +9,7 @@ exports.default = void 0;
|
|
|
7
9
|
|
|
8
10
|
var _lodash = require("lodash");
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var _store = _interopRequireDefault(require("./store"));
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* External dependencies
|
|
@@ -30,8 +32,9 @@ var _name = require("./store/name");
|
|
|
30
32
|
* @return {Function} Middleware function.
|
|
31
33
|
*/
|
|
32
34
|
const createResolversCacheMiddleware = (registry, reducerKey) => () => next => action => {
|
|
33
|
-
const resolvers = registry.select(
|
|
34
|
-
Object.entries(resolvers).forEach(
|
|
35
|
+
const resolvers = registry.select(_store.default).getCachedResolvers(reducerKey);
|
|
36
|
+
Object.entries(resolvers).forEach(_ref => {
|
|
37
|
+
let [selectorName, resolversByArgs] = _ref;
|
|
35
38
|
const resolver = (0, _lodash.get)(registry.stores, [reducerKey, 'resolvers', selectorName]);
|
|
36
39
|
|
|
37
40
|
if (!resolver || !resolver.shouldInvalidate) {
|
|
@@ -47,7 +50,7 @@ const createResolversCacheMiddleware = (registry, reducerKey) => () => next => a
|
|
|
47
50
|
} // Trigger cache invalidation
|
|
48
51
|
|
|
49
52
|
|
|
50
|
-
registry.dispatch(
|
|
53
|
+
registry.dispatch(_store.default).invalidateResolution(reducerKey, selectorName, args);
|
|
51
54
|
});
|
|
52
55
|
});
|
|
53
56
|
return next(action);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GAAG,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAClEC,IADwE,IAElEC,MAAF,IAAc;AAClB,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,QAAyC;AAAA,QAAvC,CAAEC,YAAF,EAAgBC,eAAhB,CAAuC;AACxC,UAAMC,QAAQ,GAAG,iBAAKb,QAAQ,CAACc,MAAd,EAAsB,CACtCb,UADsC,EAEtC,WAFsC,EAGtCU,YAHsC,CAAtB,CAAjB;;AAKA,QAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACE,gBAA9B,EAAiD;AAChD;AACA;;AACDH,IAAAA,eAAe,CAACF,OAAhB,CAAyB,CAAEM,KAAF,EAASC,IAAT,KAAmB;AAC3C;AACA;AACA;AACA,UACCD,KAAK,KAAK,KAAV,IACA,CAAEH,QAAQ,CAACE,gBAAT,CAA2BZ,MAA3B,EAAmC,GAAGc,IAAtC,CAFH,EAGE;AACD;AACA,OAT0C,CAW3C;;;AACAjB,MAAAA,QAAQ,CACNkB,QADF,CACYZ,cADZ,EAEEa,oBAFF,CAEwBlB,UAFxB,EAEoCU,YAFpC,EAEkDM,IAFlD;AAGA,KAfD;AAgBA,GA1BF;AA4BA,SAAOf,IAAI,CAAEC,MAAF,CAAX;AACA,CAnCD;;eAqCeJ,8B","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware = ( registry, reducerKey ) => () => (\n\tnext\n) => ( action ) => {\n\tconst resolvers = registry\n\t\t.select( coreDataStore )\n\t\t.getCachedResolvers( reducerKey );\n\tObject.entries( resolvers ).forEach(\n\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver = get( registry.stores, [\n\t\t\t\treducerKey,\n\t\t\t\t'resolvers',\n\t\t\t\tselectorName,\n\t\t\t] );\n\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t// If the value is false it means this resolver has finished its resolution which means we need to invalidate it,\n\t\t\t\t// if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif (\n\t\t\t\t\tvalue !== false ||\n\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Trigger cache invalidation\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t} );\n\t\t}\n\t);\n\treturn next( action );\n};\n\nexport default createResolversCacheMiddleware;\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -4,40 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
const coreDataStore = {
|
|
8
|
+
name: 'core/data',
|
|
9
|
+
|
|
10
|
+
instantiate(registry) {
|
|
11
|
+
const getCoreDataSelector = selectorName => function (key) {
|
|
12
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
13
|
+
args[_key - 1] = arguments[_key];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return registry.select(key)[selectorName](...args);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getCoreDataAction = actionName => function (key) {
|
|
20
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
21
|
+
args[_key2 - 1] = arguments[_key2];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return registry.dispatch(key)[actionName](...args);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
getSelectors() {
|
|
29
|
+
return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)]));
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
getActions() {
|
|
33
|
+
return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)]));
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
subscribe() {
|
|
37
|
+
// There's no reasons to trigger any listener when we subscribe to this store
|
|
38
|
+
// because there's no state stored in this store that need to retrigger selectors
|
|
39
|
+
// if a change happens, the corresponding store where the tracking stated live
|
|
40
|
+
// would have already triggered a "subscribe" call.
|
|
41
|
+
return () => () => {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
var _default = coreDataStore;
|
|
42
49
|
exports.default = _default;
|
|
43
50
|
//# sourceMappingURL=index.js.map
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE,WADe;;AAErBC,EAAAA,WAAW,CAAEC,QAAF,EAAa;AACvB,UAAMC,mBAAmB,GAAKC,YAAF,IAAoB,UAAEC,GAAF,EAAoB;AAAA,wCAAVC,IAAU;AAAVA,QAAAA,IAAU;AAAA;;AACnE,aAAOJ,QAAQ,CAACK,MAAT,CAAiBF,GAAjB,EAAwBD,YAAxB,EAAwC,GAAGE,IAA3C,CAAP;AACA,KAFD;;AAIA,UAAME,iBAAiB,GAAKC,UAAF,IAAkB,UAAEJ,GAAF,EAAoB;AAAA,yCAAVC,IAAU;AAAVA,QAAAA,IAAU;AAAA;;AAC/D,aAAOJ,QAAQ,CAACQ,QAAT,CAAmBL,GAAnB,EAA0BI,UAA1B,EAAwC,GAAGH,IAA3C,CAAP;AACA,KAFD;;AAIA,WAAO;AACNK,MAAAA,YAAY,GAAG;AACd,eAAOC,MAAM,CAACC,WAAP,CACN,CACC,gBADD,EAEC,sBAFD,EAGC,uBAHD,EAIC,aAJD,EAKC,oBALD,EAMEC,GANF,CAMSV,YAAF,IAAoB,CAC1BA,YAD0B,EAE1BD,mBAAmB,CAAEC,YAAF,CAFO,CAN3B,CADM,CAAP;AAYA,OAdK;;AAgBNW,MAAAA,UAAU,GAAG;AACZ,eAAOH,MAAM,CAACC,WAAP,CACN,CACC,iBADD,EAEC,kBAFD,EAGC,sBAHD,EAIC,8BAJD,EAKC,sCALD,EAMEC,GANF,CAMSL,UAAF,IAAkB,CACxBA,UADwB,EAExBD,iBAAiB,CAAEC,UAAF,CAFO,CANzB,CADM,CAAP;AAYA,OA7BK;;AA+BNO,MAAAA,SAAS,GAAG;AACX;AACA;AACA;AACA;AACA,eAAO,MAAM,MAAM,CAAE,CAArB;AACA;;AArCK,KAAP;AAuCA;;AAlDoB,CAAtB;eAqDejB,a","sourcesContent":["const coreDataStore = {\n\tname: 'core/data',\n\tinstantiate( registry ) {\n\t\tconst getCoreDataSelector = ( selectorName ) => ( key, ...args ) => {\n\t\t\treturn registry.select( key )[ selectorName ]( ...args );\n\t\t};\n\n\t\tconst getCoreDataAction = ( actionName ) => ( key, ...args ) => {\n\t\t\treturn registry.dispatch( key )[ actionName ]( ...args );\n\t\t};\n\n\t\treturn {\n\t\t\tgetSelectors() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'getIsResolving',\n\t\t\t\t\t\t'hasStartedResolution',\n\t\t\t\t\t\t'hasFinishedResolution',\n\t\t\t\t\t\t'isResolving',\n\t\t\t\t\t\t'getCachedResolvers',\n\t\t\t\t\t].map( ( selectorName ) => [\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tgetCoreDataSelector( selectorName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tgetActions() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'startResolution',\n\t\t\t\t\t\t'finishResolution',\n\t\t\t\t\t\t'invalidateResolution',\n\t\t\t\t\t\t'invalidateResolutionForStore',\n\t\t\t\t\t\t'invalidateResolutionForStoreSelector',\n\t\t\t\t\t].map( ( actionName ) => [\n\t\t\t\t\t\tactionName,\n\t\t\t\t\t\tgetCoreDataAction( actionName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tsubscribe() {\n\t\t\t\t// There's no reasons to trigger any listener when we subscribe to this store\n\t\t\t\t// because there's no state stored in this store that need to retrigger selectors\n\t\t\t\t// if a change happens, the corresponding store where the tracking stated live\n\t\t\t\t// would have already triggered a \"subscribe\" call.\n\t\t\t\treturn () => () => {};\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport default coreDataStore;\n"]}
|
package/build/types.js
CHANGED
package/build/utils/emitter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/utils/emitter.js"],"names":["createEmitter","isPaused","isPending","listeners","Set","notifyListeners","Array","from","forEach","listener","subscribe","add","delete","pause","resume","emit"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,GAAyB;AAC/B,MAAIC,QAAQ,GAAG,KAAf;AACA,MAAIC,SAAS,GAAG,KAAhB;AACA,QAAMC,SAAS,GAAG,IAAIC,GAAJ,EAAlB;;AACA,QAAMC,eAAe,GAAG,MACvB;AACA;AACA;AACAC,EAAAA,KAAK,CAACC,IAAN,CAAYJ,SAAZ,EAAwBK,OAAxB,CAAmCC,QAAF,IAAgBA,QAAQ,EAAzD,CAJD;;AAMA,SAAO;AACN,QAAIR,QAAJ,GAAe;AACd,aAAOA,QAAP;AACA,KAHK;;AAKNS,IAAAA,SAAS,CAAED,QAAF,EAAa;AACrBN,MAAAA,SAAS,CAACQ,GAAV,CAAeF,QAAf;AACA,aAAO,MAAMN,SAAS,CAACS,MAAV,CAAkBH,QAAlB,CAAb;AACA,KARK;;AAUNI,IAAAA,KAAK,GAAG;AACPZ,MAAAA,QAAQ,GAAG,IAAX;AACA,KAZK;;AAcNa,IAAAA,MAAM,GAAG;AACRb,MAAAA,QAAQ,GAAG,KAAX;;AACA,UAAKC,SAAL,EAAiB;AAChBA,QAAAA,SAAS,GAAG,KAAZ;AACAG,QAAAA,eAAe;AACf;AACD,KApBK;;AAsBNU,IAAAA,IAAI,GAAG;AACN,UAAKd,QAAL,EAAgB;AACfC,QAAAA,SAAS,GAAG,IAAZ;AACA;AACA;;AACDG,MAAAA,eAAe;AACf;;AA5BK,GAAP;AA8BA","sourcesContent":["/**\n * Create an event emitter.\n *\n * @return {import(\"../types\").
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/utils/emitter.js"],"names":["createEmitter","isPaused","isPending","listeners","Set","notifyListeners","Array","from","forEach","listener","subscribe","add","delete","pause","resume","emit"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,GAAyB;AAC/B,MAAIC,QAAQ,GAAG,KAAf;AACA,MAAIC,SAAS,GAAG,KAAhB;AACA,QAAMC,SAAS,GAAG,IAAIC,GAAJ,EAAlB;;AACA,QAAMC,eAAe,GAAG,MACvB;AACA;AACA;AACAC,EAAAA,KAAK,CAACC,IAAN,CAAYJ,SAAZ,EAAwBK,OAAxB,CAAmCC,QAAF,IAAgBA,QAAQ,EAAzD,CAJD;;AAMA,SAAO;AACN,QAAIR,QAAJ,GAAe;AACd,aAAOA,QAAP;AACA,KAHK;;AAKNS,IAAAA,SAAS,CAAED,QAAF,EAAa;AACrBN,MAAAA,SAAS,CAACQ,GAAV,CAAeF,QAAf;AACA,aAAO,MAAMN,SAAS,CAACS,MAAV,CAAkBH,QAAlB,CAAb;AACA,KARK;;AAUNI,IAAAA,KAAK,GAAG;AACPZ,MAAAA,QAAQ,GAAG,IAAX;AACA,KAZK;;AAcNa,IAAAA,MAAM,GAAG;AACRb,MAAAA,QAAQ,GAAG,KAAX;;AACA,UAAKC,SAAL,EAAiB;AAChBA,QAAAA,SAAS,GAAG,KAAZ;AACAG,QAAAA,eAAe;AACf;AACD,KApBK;;AAsBNU,IAAAA,IAAI,GAAG;AACN,UAAKd,QAAL,EAAgB;AACfC,QAAAA,SAAS,GAAG,IAAZ;AACA;AACA;;AACDG,MAAAA,eAAe;AACf;;AA5BK,GAAP;AA8BA","sourcesContent":["/**\n * Create an event emitter.\n *\n * @return {import(\"../types\").DataEmitter} Emitter.\n */\nexport function createEmitter() {\n\tlet isPaused = false;\n\tlet isPending = false;\n\tconst listeners = new Set();\n\tconst notifyListeners = () =>\n\t\t// We use Array.from to clone the listeners Set\n\t\t// This ensures that we don't run a listener\n\t\t// that was added as a response to another listener.\n\t\tArray.from( listeners ).forEach( ( listener ) => listener() );\n\n\treturn {\n\t\tget isPaused() {\n\t\t\treturn isPaused;\n\t\t},\n\n\t\tsubscribe( listener ) {\n\t\t\tlisteners.add( listener );\n\t\t\treturn () => listeners.delete( listener );\n\t\t},\n\n\t\tpause() {\n\t\t\tisPaused = true;\n\t\t},\n\n\t\tresume() {\n\t\t\tisPaused = false;\n\t\t\tif ( isPending ) {\n\t\t\t\tisPending = false;\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t},\n\n\t\temit() {\n\t\t\tif ( isPaused ) {\n\t\t\t\tisPending = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnotifyListeners();\n\t\t},\n\t};\n}\n"]}
|
|
@@ -42,7 +42,9 @@ const useDispatchWithMap = (dispatchMap, deps) => {
|
|
|
42
42
|
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
return (
|
|
45
|
+
return function () {
|
|
46
|
+
return currentDispatchMap.current(registry.dispatch, registry)[propName](...arguments);
|
|
47
|
+
};
|
|
46
48
|
});
|
|
47
49
|
}, [registry, ...deps]);
|
|
48
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["mapValues","useMemo","useRef","useIsomorphicLayoutEffect","useRegistry","useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","dispatcher","propName","console","warn"
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["mapValues","useMemo","useRef","useIsomorphicLayoutEffect","useRegistry","useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","dispatcher","propName","console","warn"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,OAAT,EAAkBC,MAAlB,QAAgC,oBAAhC;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACnD,QAAMC,QAAQ,GAAGJ,WAAW,EAA5B;AACA,QAAMK,kBAAkB,GAAGP,MAAM,CAAEI,WAAF,CAAjC;AAEAH,EAAAA,yBAAyB,CAAE,MAAM;AAChCM,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BJ,WAA7B;AACA,GAFwB,CAAzB;AAIA,SAAOL,OAAO,CAAE,MAAM;AACrB,UAAMU,oBAAoB,GAAGF,kBAAkB,CAACC,OAAnB,CAC5BF,QAAQ,CAACI,QADmB,EAE5BJ,QAF4B,CAA7B;AAIA,WAAOR,SAAS,CAAEW,oBAAF,EAAwB,CAAEE,UAAF,EAAcC,QAAd,KAA4B;AACnE,UAAK,OAAOD,UAAP,KAAsB,UAA3B,EAAwC;AACvC;AACAE,QAAAA,OAAO,CAACC,IAAR,CACE,YAAYF,QAAU,sEADxB;AAGA;;AACD,aAAO;AAAA,eACNL,kBAAkB,CAChBC,OADF,CACWF,QAAQ,CAACI,QADpB,EAC8BJ,QAD9B,EAEGM,QAFH,EAEe,YAFf,CADM;AAAA,OAAP;AAIA,KAXe,CAAhB;AAYA,GAjBa,EAiBX,CAAEN,QAAF,EAAY,GAAGD,IAAf,CAjBW,CAAd;AAkBA,CA1BD;;AA4BA,eAAeF,kBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn mapValues( currentDispatchProps, ( dispatcher, propName ) => {\n\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ( ...args ) =>\n\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t[ propName ]( ...args );\n\t\t} );\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import useRegistry from '../registry-provider/use-registry';
|
|
5
|
-
/** @typedef {import('
|
|
5
|
+
/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A custom react hook returning the current registry dispatch actions creators.
|
|
@@ -10,11 +10,11 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
10
10
|
* Note: The component using this hook must be within the context of a
|
|
11
11
|
* RegistryProvider.
|
|
12
12
|
*
|
|
13
|
-
* @param {string|
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* @param {string|StoreDescriptor} [storeNameOrDescriptor] Optionally provide the name of the
|
|
14
|
+
* store or its descriptor from which to
|
|
15
|
+
* retrieve action creators. If not
|
|
16
|
+
* provided, the registry.dispatch
|
|
17
|
+
* function is returned instead.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* This illustrates a pattern where you may need to retrieve dynamic data from
|
|
@@ -49,11 +49,11 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
49
49
|
* @return {Function} A custom react hook.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
const useDispatch =
|
|
52
|
+
const useDispatch = storeNameOrDescriptor => {
|
|
53
53
|
const {
|
|
54
54
|
dispatch
|
|
55
55
|
} = useRegistry();
|
|
56
|
-
return
|
|
56
|
+
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
export default useDispatch;
|