@wordpress/data 10.32.0 → 10.32.1-next.47f435fc9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/async-mode-provider/context.js +35 -54
- package/build/components/async-mode-provider/context.js.map +7 -1
- package/build/components/async-mode-provider/index.js +40 -25
- package/build/components/async-mode-provider/index.js.map +7 -1
- package/build/components/async-mode-provider/use-async-mode.js +25 -16
- package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build/components/registry-provider/context.js +46 -64
- package/build/components/registry-provider/context.js.map +7 -1
- package/build/components/registry-provider/index.js +40 -25
- package/build/components/registry-provider/index.js.map +7 -1
- package/build/components/registry-provider/use-registry.js +25 -55
- package/build/components/registry-provider/use-registry.js.map +7 -1
- package/build/components/use-dispatch/index.js +38 -17
- package/build/components/use-dispatch/index.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch.js +36 -71
- package/build/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build/components/use-select/index.js +79 -208
- package/build/components/use-select/index.js.map +7 -1
- package/build/components/with-dispatch/index.js +34 -107
- package/build/components/with-dispatch/index.js.map +7 -1
- package/build/components/with-registry/index.js +30 -30
- package/build/components/with-registry/index.js.map +7 -1
- package/build/components/with-select/index.js +44 -67
- package/build/components/with-select/index.js.map +7 -1
- package/build/controls.js +49 -110
- package/build/controls.js.map +7 -1
- package/build/create-selector.js +36 -11
- package/build/create-selector.js.map +7 -1
- package/build/default-registry.js +24 -10
- package/build/default-registry.js.map +7 -1
- package/build/dispatch.js +38 -31
- package/build/dispatch.js.map +7 -1
- package/build/factory.js +29 -85
- package/build/factory.js.map +7 -1
- package/build/index.js +114 -301
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/plugins/index.js +36 -11
- package/build/plugins/index.js.map +7 -1
- package/build/plugins/persistence/index.js +74 -139
- package/build/plugins/persistence/index.js.map +7 -1
- package/build/plugins/persistence/storage/default.js +37 -18
- package/build/plugins/persistence/storage/default.js.map +7 -1
- package/build/plugins/persistence/storage/object.js +24 -7
- package/build/plugins/persistence/storage/object.js.map +7 -1
- package/build/promise-middleware.js +37 -20
- package/build/promise-middleware.js.map +7 -1
- package/build/redux-store/combine-reducers.js +26 -5
- package/build/redux-store/combine-reducers.js.map +7 -1
- package/build/redux-store/index.js +221 -331
- package/build/redux-store/index.js.map +7 -1
- package/build/redux-store/metadata/actions.js +51 -112
- package/build/redux-store/metadata/actions.js.map +7 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build/redux-store/metadata/reducer.js +111 -115
- package/build/redux-store/metadata/reducer.js.map +7 -1
- package/build/redux-store/metadata/selectors.js +109 -181
- package/build/redux-store/metadata/selectors.js.map +7 -1
- package/build/redux-store/metadata/utils.js +32 -35
- package/build/redux-store/metadata/utils.js.map +7 -1
- package/build/redux-store/thunk-middleware.js +24 -7
- package/build/redux-store/thunk-middleware.js.map +7 -1
- package/build/registry.js +94 -198
- package/build/registry.js.map +7 -1
- package/build/resolvers-cache-middleware.js +26 -27
- package/build/resolvers-cache-middleware.js.map +7 -1
- package/build/select.js +38 -31
- package/build/select.js.map +7 -1
- package/build/store/index.js +52 -16
- package/build/store/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/emitter.js +33 -16
- package/build/utils/emitter.js.map +7 -1
- package/build-module/components/async-mode-provider/context.js +12 -49
- package/build-module/components/async-mode-provider/context.js.map +7 -1
- package/build-module/components/async-mode-provider/index.js +8 -3
- package/build-module/components/async-mode-provider/index.js.map +7 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
- package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build-module/components/registry-provider/context.js +13 -58
- package/build-module/components/registry-provider/context.js.map +7 -1
- package/build-module/components/registry-provider/index.js +8 -3
- package/build-module/components/registry-provider/index.js.map +7 -1
- package/build-module/components/registry-provider/use-registry.js +7 -51
- package/build-module/components/registry-provider/use-registry.js.map +7 -1
- package/build-module/components/use-dispatch/index.js +7 -3
- package/build-module/components/use-dispatch/index.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -66
- package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build-module/components/use-select/index.js +45 -193
- package/build-module/components/use-select/index.js.map +7 -1
- package/build-module/components/with-dispatch/index.js +16 -104
- package/build-module/components/with-dispatch/index.js.map +7 -1
- package/build-module/components/with-registry/index.js +12 -27
- package/build-module/components/with-registry/index.js.map +7 -1
- package/build-module/components/with-select/index.js +16 -63
- package/build-module/components/with-select/index.js.map +7 -1
- package/build-module/controls.js +25 -105
- package/build-module/controls.js.map +7 -1
- package/build-module/create-selector.js +5 -8
- package/build-module/create-selector.js.map +7 -1
- package/build-module/default-registry.js +6 -6
- package/build-module/default-registry.js.map +7 -1
- package/build-module/dispatch.js +6 -27
- package/build-module/dispatch.js.map +7 -1
- package/build-module/factory.js +8 -82
- package/build-module/factory.js.map +7 -1
- package/build-module/index.js +62 -185
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/plugins/index.js +5 -2
- package/build-module/plugins/index.js.map +7 -1
- package/build-module/plugins/persistence/index.js +38 -129
- package/build-module/plugins/persistence/index.js.map +7 -1
- package/build-module/plugins/persistence/storage/default.js +8 -11
- package/build-module/plugins/persistence/storage/default.js.map +7 -1
- package/build-module/plugins/persistence/storage/object.js +6 -3
- package/build-module/plugins/persistence/storage/object.js.map +7 -1
- package/build-module/promise-middleware.js +8 -14
- package/build-module/promise-middleware.js.map +7 -1
- package/build-module/redux-store/combine-reducers.js +5 -2
- package/build-module/redux-store/combine-reducers.js.map +7 -1
- package/build-module/redux-store/index.js +180 -310
- package/build-module/redux-store/index.js.map +7 -1
- package/build-module/redux-store/metadata/actions.js +30 -109
- package/build-module/redux-store/metadata/actions.js.map +7 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build-module/redux-store/metadata/reducer.js +83 -108
- package/build-module/redux-store/metadata/reducer.js.map +7 -1
- package/build-module/redux-store/metadata/selectors.js +76 -175
- package/build-module/redux-store/metadata/selectors.js.map +7 -1
- package/build-module/redux-store/metadata/utils.js +10 -30
- package/build-module/redux-store/metadata/utils.js.map +7 -1
- package/build-module/redux-store/thunk-middleware.js +7 -4
- package/build-module/redux-store/thunk-middleware.js.map +7 -1
- package/build-module/registry.js +56 -187
- package/build-module/registry.js.map +7 -1
- package/build-module/resolvers-cache-middleware.js +8 -23
- package/build-module/resolvers-cache-middleware.js.map +7 -1
- package/build-module/select.js +6 -27
- package/build-module/select.js.map +7 -1
- package/build-module/store/index.js +34 -12
- package/build-module/store/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/emitter.js +12 -13
- package/build-module/utils/emitter.js.map +7 -1
- package/package.json +17 -10
package/build-module/registry.js
CHANGED
|
@@ -1,108 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import createReduxStore from './redux-store';
|
|
10
|
-
import coreDataStore from './store';
|
|
11
|
-
import { createEmitter } from './utils/emitter';
|
|
12
|
-
import { lock, unlock } from './lock-unlock';
|
|
13
|
-
|
|
14
|
-
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.
|
|
18
|
-
*
|
|
19
|
-
* @property {Function} registerGenericStore Given a namespace key and settings
|
|
20
|
-
* object, registers a new generic
|
|
21
|
-
* store.
|
|
22
|
-
* @property {Function} registerStore Given a namespace key and settings
|
|
23
|
-
* object, registers a new namespace
|
|
24
|
-
* store.
|
|
25
|
-
* @property {Function} subscribe Given a function callback, invokes
|
|
26
|
-
* the callback on any change to state
|
|
27
|
-
* within any registered store.
|
|
28
|
-
* @property {Function} select Given a namespace key, returns an
|
|
29
|
-
* object of the store's registered
|
|
30
|
-
* selectors.
|
|
31
|
-
* @property {Function} dispatch Given a namespace key, returns an
|
|
32
|
-
* object of the store's registered
|
|
33
|
-
* action dispatchers.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @typedef {Object} WPDataPlugin An object of registry function overrides.
|
|
38
|
-
*
|
|
39
|
-
* @property {Function} registerStore registers store.
|
|
40
|
-
*/
|
|
41
|
-
|
|
1
|
+
import deprecated from "@wordpress/deprecated";
|
|
2
|
+
import createReduxStore from "./redux-store";
|
|
3
|
+
import coreDataStore from "./store";
|
|
4
|
+
import { createEmitter } from "./utils/emitter";
|
|
5
|
+
import { lock, unlock } from "./lock-unlock";
|
|
42
6
|
function getStoreName(storeNameOrDescriptor) {
|
|
43
|
-
return typeof storeNameOrDescriptor ===
|
|
7
|
+
return typeof storeNameOrDescriptor === "string" ? storeNameOrDescriptor : storeNameOrDescriptor.name;
|
|
44
8
|
}
|
|
45
|
-
|
|
46
|
-
* Creates a new store registry, given an optional object of initial store
|
|
47
|
-
* configurations.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} storeConfigs Initial store configurations.
|
|
50
|
-
* @param {?Object} parent Parent registry.
|
|
51
|
-
*
|
|
52
|
-
* @return {WPDataRegistry} Data registry.
|
|
53
|
-
*/
|
|
54
|
-
export function createRegistry(storeConfigs = {}, parent = null) {
|
|
9
|
+
function createRegistry(storeConfigs = {}, parent = null) {
|
|
55
10
|
const stores = {};
|
|
56
11
|
const emitter = createEmitter();
|
|
57
12
|
let listeningStores = null;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Global listener called for each store's update.
|
|
61
|
-
*/
|
|
62
13
|
function globalListener() {
|
|
63
14
|
emitter.emit();
|
|
64
15
|
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Subscribe to changes to any data, either in all stores in registry, or
|
|
68
|
-
* in one specific store.
|
|
69
|
-
*
|
|
70
|
-
* @param {Function} listener Listener function.
|
|
71
|
-
* @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.
|
|
72
|
-
*
|
|
73
|
-
* @return {Function} Unsubscribe function.
|
|
74
|
-
*/
|
|
75
16
|
const subscribe = (listener, storeNameOrDescriptor) => {
|
|
76
|
-
// subscribe to all stores
|
|
77
17
|
if (!storeNameOrDescriptor) {
|
|
78
18
|
return emitter.subscribe(listener);
|
|
79
19
|
}
|
|
80
|
-
|
|
81
|
-
// subscribe to one store
|
|
82
20
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
83
21
|
const store = stores[storeName];
|
|
84
22
|
if (store) {
|
|
85
23
|
return store.subscribe(listener);
|
|
86
24
|
}
|
|
87
|
-
|
|
88
|
-
// Trying to access a store that hasn't been registered,
|
|
89
|
-
// this is a pattern rarely used but seen in some places.
|
|
90
|
-
// We fallback to global `subscribe` here for backward-compatibility for now.
|
|
91
|
-
// See https://github.com/WordPress/gutenberg/pull/27466 for more info.
|
|
92
25
|
if (!parent) {
|
|
93
26
|
return emitter.subscribe(listener);
|
|
94
27
|
}
|
|
95
28
|
return parent.subscribe(listener, storeNameOrDescriptor);
|
|
96
29
|
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Calls a selector given the current state and extra arguments.
|
|
100
|
-
*
|
|
101
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
102
|
-
* or the store descriptor.
|
|
103
|
-
*
|
|
104
|
-
* @return {*} The selector's returned value.
|
|
105
|
-
*/
|
|
106
30
|
function select(storeNameOrDescriptor) {
|
|
107
31
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
108
32
|
listeningStores?.add(storeName);
|
|
@@ -113,7 +37,7 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
113
37
|
return parent?.select(storeName);
|
|
114
38
|
}
|
|
115
39
|
function __unstableMarkListeningStores(callback, ref) {
|
|
116
|
-
listeningStores = new Set();
|
|
40
|
+
listeningStores = /* @__PURE__ */ new Set();
|
|
117
41
|
try {
|
|
118
42
|
return callback.call(this);
|
|
119
43
|
} finally {
|
|
@@ -121,18 +45,6 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
121
45
|
listeningStores = null;
|
|
122
46
|
}
|
|
123
47
|
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to
|
|
127
|
-
* state so that you only need to supply additional arguments, and modified so that they return
|
|
128
|
-
* promises that resolve to their eventual values, after any resolvers have ran.
|
|
129
|
-
*
|
|
130
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
131
|
-
* convention of passing the store name is
|
|
132
|
-
* also supported.
|
|
133
|
-
*
|
|
134
|
-
* @return {Object} Each key of the object matches the name of a selector.
|
|
135
|
-
*/
|
|
136
48
|
function resolveSelect(storeNameOrDescriptor) {
|
|
137
49
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
138
50
|
listeningStores?.add(storeName);
|
|
@@ -142,18 +54,6 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
142
54
|
}
|
|
143
55
|
return parent && parent.resolveSelect(storeName);
|
|
144
56
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to
|
|
148
|
-
* state so that you only need to supply additional arguments, and modified so that they throw
|
|
149
|
-
* promises in case the selector is not resolved yet.
|
|
150
|
-
*
|
|
151
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
152
|
-
* convention of passing the store name is
|
|
153
|
-
* also supported.
|
|
154
|
-
*
|
|
155
|
-
* @return {Object} Object containing the store's suspense-wrapped selectors.
|
|
156
|
-
*/
|
|
157
57
|
function suspendSelect(storeNameOrDescriptor) {
|
|
158
58
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
159
59
|
listeningStores?.add(storeName);
|
|
@@ -163,15 +63,6 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
163
63
|
}
|
|
164
64
|
return parent && parent.suspendSelect(storeName);
|
|
165
65
|
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns the available actions for a part of the state.
|
|
169
|
-
*
|
|
170
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
171
|
-
* or the store descriptor.
|
|
172
|
-
*
|
|
173
|
-
* @return {*} The action's returned value.
|
|
174
|
-
*/
|
|
175
66
|
function dispatch(storeNameOrDescriptor) {
|
|
176
67
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
177
68
|
const store = stores[storeName];
|
|
@@ -180,49 +71,39 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
180
71
|
}
|
|
181
72
|
return parent && parent.dispatch(storeName);
|
|
182
73
|
}
|
|
183
|
-
|
|
184
|
-
//
|
|
185
|
-
// Deprecated
|
|
186
|
-
// TODO: Remove this after `use()` is removed.
|
|
187
74
|
function withPlugins(attributes) {
|
|
188
|
-
return Object.fromEntries(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
75
|
+
return Object.fromEntries(
|
|
76
|
+
Object.entries(attributes).map(([key, attribute]) => {
|
|
77
|
+
if (typeof attribute !== "function") {
|
|
78
|
+
return [key, attribute];
|
|
79
|
+
}
|
|
80
|
+
return [
|
|
81
|
+
key,
|
|
82
|
+
function() {
|
|
83
|
+
return registry[key].apply(null, arguments);
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
})
|
|
87
|
+
);
|
|
196
88
|
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Registers a store instance.
|
|
200
|
-
*
|
|
201
|
-
* @param {string} name Store registry name.
|
|
202
|
-
* @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).
|
|
203
|
-
*/
|
|
204
89
|
function registerStoreInstance(name, createStore) {
|
|
205
90
|
if (stores[name]) {
|
|
206
|
-
// eslint-disable-next-line no-console
|
|
207
91
|
console.error('Store "' + name + '" is already registered.');
|
|
208
92
|
return stores[name];
|
|
209
93
|
}
|
|
210
94
|
const store = createStore();
|
|
211
|
-
if (typeof store.getSelectors !==
|
|
212
|
-
throw new TypeError(
|
|
95
|
+
if (typeof store.getSelectors !== "function") {
|
|
96
|
+
throw new TypeError("store.getSelectors must be a function");
|
|
213
97
|
}
|
|
214
|
-
if (typeof store.getActions !==
|
|
215
|
-
throw new TypeError(
|
|
98
|
+
if (typeof store.getActions !== "function") {
|
|
99
|
+
throw new TypeError("store.getActions must be a function");
|
|
216
100
|
}
|
|
217
|
-
if (typeof store.subscribe !==
|
|
218
|
-
throw new TypeError(
|
|
101
|
+
if (typeof store.subscribe !== "function") {
|
|
102
|
+
throw new TypeError("store.subscribe must be a function");
|
|
219
103
|
}
|
|
220
|
-
// The emitter is used to keep track of active listeners when the registry
|
|
221
|
-
// get paused, that way, when resumed we should be able to call all these
|
|
222
|
-
// pending listeners.
|
|
223
104
|
store.emitter = createEmitter();
|
|
224
105
|
const currentSubscribe = store.subscribe;
|
|
225
|
-
store.subscribe = listener => {
|
|
106
|
+
store.subscribe = (listener) => {
|
|
226
107
|
const unsubscribeFromEmitter = store.emitter.subscribe(listener);
|
|
227
108
|
const unsubscribeFromStore = currentSubscribe(() => {
|
|
228
109
|
if (store.emitter.isPaused) {
|
|
@@ -238,65 +119,56 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
238
119
|
};
|
|
239
120
|
stores[name] = store;
|
|
240
121
|
store.subscribe(globalListener);
|
|
241
|
-
|
|
242
|
-
// Copy private actions and selectors from the parent store.
|
|
243
122
|
if (parent) {
|
|
244
123
|
try {
|
|
245
|
-
unlock(store.store).registerPrivateActions(
|
|
246
|
-
|
|
124
|
+
unlock(store.store).registerPrivateActions(
|
|
125
|
+
unlock(parent).privateActionsOf(name)
|
|
126
|
+
);
|
|
127
|
+
unlock(store.store).registerPrivateSelectors(
|
|
128
|
+
unlock(parent).privateSelectorsOf(name)
|
|
129
|
+
);
|
|
247
130
|
} catch (e) {
|
|
248
|
-
// unlock() throws if store.store was not locked.
|
|
249
|
-
// The error indicates there's nothing to do here so let's
|
|
250
|
-
// ignore it.
|
|
251
131
|
}
|
|
252
132
|
}
|
|
253
133
|
return store;
|
|
254
134
|
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Registers a new store given a store descriptor.
|
|
258
|
-
*
|
|
259
|
-
* @param {StoreDescriptor} store Store descriptor.
|
|
260
|
-
*/
|
|
261
135
|
function register(store) {
|
|
262
|
-
registerStoreInstance(
|
|
136
|
+
registerStoreInstance(
|
|
137
|
+
store.name,
|
|
138
|
+
() => store.instantiate(registry)
|
|
139
|
+
);
|
|
263
140
|
}
|
|
264
141
|
function registerGenericStore(name, store) {
|
|
265
|
-
deprecated(
|
|
266
|
-
since:
|
|
267
|
-
alternative:
|
|
142
|
+
deprecated("wp.data.registerGenericStore", {
|
|
143
|
+
since: "5.9",
|
|
144
|
+
alternative: "wp.data.register( storeDescriptor )"
|
|
268
145
|
});
|
|
269
146
|
registerStoreInstance(name, () => store);
|
|
270
147
|
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Registers a standard `@wordpress/data` store.
|
|
274
|
-
*
|
|
275
|
-
* @param {string} storeName Unique namespace identifier.
|
|
276
|
-
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
277
|
-
*
|
|
278
|
-
* @return {Object} Registered store object.
|
|
279
|
-
*/
|
|
280
148
|
function registerStore(storeName, options) {
|
|
281
149
|
if (!options.reducer) {
|
|
282
|
-
throw new TypeError(
|
|
150
|
+
throw new TypeError("Must specify store reducer");
|
|
283
151
|
}
|
|
284
|
-
const store = registerStoreInstance(
|
|
152
|
+
const store = registerStoreInstance(
|
|
153
|
+
storeName,
|
|
154
|
+
() => createReduxStore(storeName, options).instantiate(registry)
|
|
155
|
+
);
|
|
285
156
|
return store.store;
|
|
286
157
|
}
|
|
287
158
|
function batch(callback) {
|
|
288
|
-
// If we're already batching, just call the callback.
|
|
289
159
|
if (emitter.isPaused) {
|
|
290
160
|
callback();
|
|
291
161
|
return;
|
|
292
162
|
}
|
|
293
163
|
emitter.pause();
|
|
294
|
-
Object.values(stores).forEach(store => store.emitter.pause());
|
|
164
|
+
Object.values(stores).forEach((store) => store.emitter.pause());
|
|
295
165
|
try {
|
|
296
166
|
callback();
|
|
297
167
|
} finally {
|
|
298
168
|
emitter.resume();
|
|
299
|
-
Object.values(stores).forEach(
|
|
169
|
+
Object.values(stores).forEach(
|
|
170
|
+
(store) => store.emitter.resume()
|
|
171
|
+
);
|
|
300
172
|
}
|
|
301
173
|
}
|
|
302
174
|
let registry = {
|
|
@@ -315,10 +187,6 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
315
187
|
registerStore,
|
|
316
188
|
__unstableMarkListeningStores
|
|
317
189
|
};
|
|
318
|
-
|
|
319
|
-
//
|
|
320
|
-
// TODO:
|
|
321
|
-
// This function will be deprecated as soon as it is no longer internally referenced.
|
|
322
190
|
function use(plugin, options) {
|
|
323
191
|
if (!plugin) {
|
|
324
192
|
return;
|
|
@@ -338,16 +206,14 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
338
206
|
}
|
|
339
207
|
const registryWithPlugins = withPlugins(registry);
|
|
340
208
|
lock(registryWithPlugins, {
|
|
341
|
-
privateActionsOf: name => {
|
|
209
|
+
privateActionsOf: (name) => {
|
|
342
210
|
try {
|
|
343
211
|
return unlock(stores[name].store).privateActions;
|
|
344
212
|
} catch (e) {
|
|
345
|
-
// unlock() throws an error the store was not locked – this means
|
|
346
|
-
// there no private actions are available
|
|
347
213
|
return {};
|
|
348
214
|
}
|
|
349
215
|
},
|
|
350
|
-
privateSelectorsOf: name => {
|
|
216
|
+
privateSelectorsOf: (name) => {
|
|
351
217
|
try {
|
|
352
218
|
return unlock(stores[name].store).privateSelectors;
|
|
353
219
|
} catch (e) {
|
|
@@ -357,4 +223,7 @@ export function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
357
223
|
});
|
|
358
224
|
return registryWithPlugins;
|
|
359
225
|
}
|
|
360
|
-
|
|
226
|
+
export {
|
|
227
|
+
createRegistry
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["deprecated","createReduxStore","coreDataStore","createEmitter","lock","unlock","getStoreName","storeNameOrDescriptor","name","createRegistry","storeConfigs","parent","stores","emitter","listeningStores","globalListener","emit","subscribe","listener","storeName","store","select","add","getSelectors","__unstableMarkListeningStores","callback","ref","Set","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","Object","fromEntries","entries","map","key","attribute","registry","apply","arguments","registerStoreInstance","createStore","console","error","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","registerPrivateActions","privateActionsOf","registerPrivateSelectors","privateSelectorsOf","e","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","batch","pause","values","forEach","resume","namespaces","use","plugin","config","registryWithPlugins","privateActions","privateSelectors"],"sources":["@wordpress/data/src/registry.js"],"sourcesContent":["/**\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';\nimport { lock, unlock } from './lock-unlock';\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\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\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\tlet listeningStores = null;\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, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\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 global `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 emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\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 = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.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?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\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 = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.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 * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( 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 = getStoreName( 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\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\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 {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\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\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\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, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\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 = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\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\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\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\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\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\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked – this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,OAAOC,gBAAgB,MAAM,eAAe;AAC5C,OAAOC,aAAa,MAAM,SAAS;AACnC,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,IAAI,EAAEC,MAAM,QAAQ,eAAe;;AAE5C;;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,SAASC,YAAYA,CAAEC,qBAAqB,EAAG;EAC9C,OAAO,OAAOA,qBAAqB,KAAK,QAAQ,GAC7CA,qBAAqB,GACrBA,qBAAqB,CAACC,IAAI;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAA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,OAAO,CAAC,CAAC;MACV;IACD;EACD,CAAE,CAAC;EACH,OAAOkB,mBAAmB;AAC3B","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/registry.js"],
|
|
4
|
+
"sourcesContent": ["/**\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';\nimport { lock, unlock } from './lock-unlock';\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\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\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\tlet listeningStores = null;\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, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\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 global `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 emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\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 = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.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?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\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 = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.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 * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( 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 = getStoreName( 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\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\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 {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\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\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\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, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\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 = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\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\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\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\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\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\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;AA8B7B,SAAS,aAAc,uBAAwB;AAC9C,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAUO,SAAS,eAAgB,eAAe,CAAC,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
|
-
* @param {WPDataRegistry} registry Registry for which to create the middleware.
|
|
7
|
-
* @param {string} storeName Name of the store for which to create the middleware.
|
|
8
|
-
*
|
|
9
|
-
* @return {Function} Middleware function.
|
|
10
|
-
*/
|
|
11
|
-
const createResolversCacheMiddleware = (registry, storeName) => () => next => action => {
|
|
1
|
+
const createResolversCacheMiddleware = (registry, storeName) => () => (next) => (action) => {
|
|
12
2
|
const resolvers = registry.select(storeName).getCachedResolvers();
|
|
13
3
|
const resolverEntries = Object.entries(resolvers);
|
|
14
4
|
resolverEntries.forEach(([selectorName, resolversByArgs]) => {
|
|
@@ -17,27 +7,22 @@ const createResolversCacheMiddleware = (registry, storeName) => () => next => ac
|
|
|
17
7
|
return;
|
|
18
8
|
}
|
|
19
9
|
resolversByArgs.forEach((value, args) => {
|
|
20
|
-
|
|
21
|
-
// to `undefined` and `map.forEach` then iterates also over these orphaned entries.
|
|
22
|
-
if (value === undefined) {
|
|
10
|
+
if (value === void 0) {
|
|
23
11
|
return;
|
|
24
12
|
}
|
|
25
|
-
|
|
26
|
-
// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.
|
|
27
|
-
// If the value is "finished" or "error" it means this resolver has finished its resolution which means we need
|
|
28
|
-
// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.
|
|
29
|
-
if (value.status !== 'finished' && value.status !== 'error') {
|
|
13
|
+
if (value.status !== "finished" && value.status !== "error") {
|
|
30
14
|
return;
|
|
31
15
|
}
|
|
32
16
|
if (!resolver.shouldInvalidate(action, ...args)) {
|
|
33
17
|
return;
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
// Trigger cache invalidation
|
|
37
19
|
registry.dispatch(storeName).invalidateResolution(selectorName, args);
|
|
38
20
|
});
|
|
39
21
|
});
|
|
40
22
|
return next(action);
|
|
41
23
|
};
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
var resolvers_cache_middleware_default = createResolversCacheMiddleware;
|
|
25
|
+
export {
|
|
26
|
+
resolvers_cache_middleware_default as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=resolvers-cache-middleware.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/resolvers-cache-middleware.js"],
|
|
4
|
+
"sourcesContent": ["/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry Registry for which to create the middleware.\n * @param {string} storeName Name of the store for which to create the middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry, storeName ) => () => ( next ) => ( action ) => {\n\t\tconst resolvers = registry.select( storeName ).getCachedResolvers();\n\t\tconst resolverEntries = Object.entries( resolvers );\n\t\tresolverEntries.forEach( ( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver =\n\t\t\t\tregistry.stores[ storeName ]?.resolvers?.[ selectorName ];\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// Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value\n\t\t\t\t// to `undefined` and `map.forEach` then iterates also over these orphaned entries.\n\t\t\t\tif ( value === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\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 \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif ( value.status !== 'finished' && value.status !== 'error' ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! resolver.shouldInvalidate( action, ...args ) ) {\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( storeName )\n\t\t\t\t\t.invalidateResolution( selectorName, args );\n\t\t\t} );\n\t\t} );\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"],
|
|
5
|
+
"mappings": "AAUA,MAAM,iCACL,CAAE,UAAU,cAAe,MAAM,CAAE,SAAU,CAAE,WAAY;AAC1D,QAAM,YAAY,SAAS,OAAQ,SAAU,EAAE,mBAAmB;AAClE,QAAM,kBAAkB,OAAO,QAAS,SAAU;AAClD,kBAAgB,QAAS,CAAE,CAAE,cAAc,eAAgB,MAAO;AACjE,UAAM,WACL,SAAS,OAAQ,SAAU,GAAG,YAAa,YAAa;AACzD,QAAK,CAAE,YAAY,CAAE,SAAS,kBAAmB;AAChD;AAAA,IACD;AACA,oBAAgB,QAAS,CAAE,OAAO,SAAU;AAG3C,UAAK,UAAU,QAAY;AAC1B;AAAA,MACD;AAKA,UAAK,MAAM,WAAW,cAAc,MAAM,WAAW,SAAU;AAC9D;AAAA,MACD;AAEA,UAAK,CAAE,SAAS,iBAAkB,QAAQ,GAAG,IAAK,GAAI;AACrD;AAAA,MACD;AAGA,eACE,SAAU,SAAU,EACpB,qBAAsB,cAAc,IAAK;AAAA,IAC5C,CAAE;AAAA,EACH,CAAE;AACF,SAAO,KAAM,MAAO;AACrB;AAED,IAAO,qCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/select.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import defaultRegistry from './default-registry';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Given a store descriptor, returns an object of the store's selectors.
|
|
9
|
-
* The selector functions are been pre-bound to pass the current state automatically.
|
|
10
|
-
* As a consumer, you need only pass arguments of the selector, if applicable.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @param storeNameOrDescriptor The store descriptor. The legacy calling convention
|
|
14
|
-
* of passing the store name is also supported.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```js
|
|
18
|
-
* import { select } from '@wordpress/data';
|
|
19
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
20
|
-
*
|
|
21
|
-
* select( myCustomStore ).getPrice( 'hammer' );
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @return Object containing the store's selectors.
|
|
25
|
-
*/
|
|
26
|
-
export function select(storeNameOrDescriptor) {
|
|
1
|
+
import defaultRegistry from "./default-registry";
|
|
2
|
+
function select(storeNameOrDescriptor) {
|
|
27
3
|
return defaultRegistry.select(storeNameOrDescriptor);
|
|
28
4
|
}
|
|
29
|
-
|
|
5
|
+
export {
|
|
6
|
+
select
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/select.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, CurriedSelectorsOf, StoreDescriptor } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention\n * of passing the store name is also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return Object containing the store's selectors.\n */\nexport function select< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: string | T\n): CurriedSelectorsOf< T > {\n\treturn defaultRegistry.select( storeNameOrDescriptor );\n}\n"],
|
|
5
|
+
"mappings": "AAIA,OAAO,qBAAqB;AAqBrB,SAAS,OACf,uBAC0B;AAC1B,SAAO,gBAAgB,OAAQ,qBAAsB;AACtD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|