@wordpress/core-data 4.0.5 → 4.0.9
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/actions.js +269 -244
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +17 -9
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +22 -10
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +18 -13
- package/build/entity-provider.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +3 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +2 -1
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/index.js +25 -5
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +4 -3
- package/build/locks/actions.js.map +1 -1
- package/build/locks/reducer.js +4 -1
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +4 -3
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +7 -5
- package/build/locks/utils.js.map +1 -1
- package/build/queried-data/actions.js +6 -3
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +1 -1
- package/build/queried-data/reducer.js +17 -6
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +2 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +77 -28
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +186 -158
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +29 -21
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +11 -4
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/index.js +8 -8
- package/build/utils/on-sub-key.js +4 -2
- package/build/utils/on-sub-key.js.map +1 -1
- package/build-module/actions.js +257 -235
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +17 -9
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +21 -9
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +17 -12
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +3 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +2 -1
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/index.js +21 -3
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +4 -3
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/reducer.js +4 -1
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +4 -3
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +5 -3
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/queried-data/actions.js +5 -2
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/reducer.js +15 -4
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +2 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +68 -20
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +185 -157
- package/build-module/resolvers.js.map +1 -1
- package/build-module/utils/forward-resolver.js +11 -4
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js +3 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/package.json +12 -12
- package/src/entities.js +12 -4
- package/src/resolvers.js +5 -0
- package/src/test/actions.js +2 -2
|
@@ -22,9 +22,10 @@ import { forwardResolver, getNormalizedCommaSeparable } from './utils';
|
|
|
22
22
|
* include with request.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
export const getAuthors = query => async
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
export const getAuthors = query => async _ref => {
|
|
26
|
+
let {
|
|
27
|
+
dispatch
|
|
28
|
+
} = _ref;
|
|
28
29
|
const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
|
|
29
30
|
const users = await apiFetch({
|
|
30
31
|
path
|
|
@@ -35,9 +36,10 @@ export const getAuthors = query => async ({
|
|
|
35
36
|
* Requests the current user from the REST API.
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
|
-
export const getCurrentUser = () => async
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
export const getCurrentUser = () => async _ref2 => {
|
|
40
|
+
let {
|
|
41
|
+
dispatch
|
|
42
|
+
} = _ref2;
|
|
41
43
|
const currentUser = await apiFetch({
|
|
42
44
|
path: '/wp/v2/users/me'
|
|
43
45
|
});
|
|
@@ -53,67 +55,73 @@ export const getCurrentUser = () => async ({
|
|
|
53
55
|
* include with request.
|
|
54
56
|
*/
|
|
55
57
|
|
|
56
|
-
export const getEntityRecord = (kind, name
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
export const getEntityRecord = function (kind, name) {
|
|
59
|
+
let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
60
|
+
let query = arguments.length > 3 ? arguments[3] : undefined;
|
|
61
|
+
return async _ref3 => {
|
|
62
|
+
let {
|
|
63
|
+
select,
|
|
64
|
+
dispatch
|
|
65
|
+
} = _ref3;
|
|
66
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
67
|
+
const entity = find(entities, {
|
|
68
|
+
kind,
|
|
69
|
+
name
|
|
70
|
+
});
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// If requesting specific fields, items and query association to said
|
|
77
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
78
|
-
// the ID.
|
|
79
|
-
query = { ...query,
|
|
80
|
-
_fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
|
|
81
|
-
};
|
|
82
|
-
} // Disable reason: While true that an early return could leave `path`
|
|
83
|
-
// unused, it's important that path is derived using the query prior to
|
|
84
|
-
// additional query modifications in the condition below, since those
|
|
85
|
-
// modifications are relevant to how the data is tracked in state, and not
|
|
86
|
-
// for how the request is made to the REST API.
|
|
87
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const path = addQueryArgs(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
|
|
91
|
-
...query
|
|
76
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
|
|
77
|
+
exclusive: false
|
|
92
78
|
});
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
query
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
try {
|
|
81
|
+
if (query !== undefined && query._fields) {
|
|
82
|
+
// If requesting specific fields, items and query association to said
|
|
83
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
84
|
+
// the ID.
|
|
85
|
+
query = { ...query,
|
|
86
|
+
_fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
|
|
87
|
+
};
|
|
88
|
+
} // Disable reason: While true that an early return could leave `path`
|
|
89
|
+
// unused, it's important that path is derived using the query prior to
|
|
90
|
+
// additional query modifications in the condition below, since those
|
|
91
|
+
// modifications are relevant to how the data is tracked in state, and not
|
|
92
|
+
// for how the request is made to the REST API.
|
|
93
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const path = addQueryArgs(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
|
|
97
|
+
...query
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (query !== undefined) {
|
|
101
|
+
query = { ...query,
|
|
102
|
+
include: [key]
|
|
103
|
+
}; // The resolution cache won't consider query as reusable based on the
|
|
104
|
+
// fields, so it's tested here, prior to initiating the REST request,
|
|
105
|
+
// and without causing `getEntityRecords` resolution to occur.
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
102
108
|
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
if (hasRecords) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
105
112
|
}
|
|
106
|
-
}
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const record = await apiFetch({
|
|
115
|
+
path
|
|
116
|
+
});
|
|
117
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
118
|
+
} catch (error) {// We need a way to handle and access REST API errors in state
|
|
119
|
+
// Until then, catching the error ensures the resolver is marked as resolved.
|
|
120
|
+
// See similar implementation in `getEntityRecords()`.
|
|
121
|
+
} finally {
|
|
122
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
117
125
|
};
|
|
118
126
|
/**
|
|
119
127
|
* Requests an entity's record from the REST API.
|
|
@@ -133,77 +141,84 @@ export const getEditedEntityRecord = forwardResolver('getEntityRecord');
|
|
|
133
141
|
* @param {Object?} query Query Object.
|
|
134
142
|
*/
|
|
135
143
|
|
|
136
|
-
export const getEntityRecords = (kind, name
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
|
|
150
|
-
exclusive: false
|
|
151
|
-
});
|
|
144
|
+
export const getEntityRecords = function (kind, name) {
|
|
145
|
+
let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
146
|
+
return async _ref4 => {
|
|
147
|
+
let {
|
|
148
|
+
dispatch
|
|
149
|
+
} = _ref4;
|
|
150
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
151
|
+
const entity = find(entities, {
|
|
152
|
+
kind,
|
|
153
|
+
name
|
|
154
|
+
});
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (query._fields) {
|
|
157
|
-
// If requesting specific fields, items and query association to said
|
|
158
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
159
|
-
// the ID.
|
|
160
|
-
query = { ...query,
|
|
161
|
-
_fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
|
|
162
|
-
};
|
|
156
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
157
|
+
return;
|
|
163
158
|
}
|
|
164
159
|
|
|
165
|
-
const
|
|
166
|
-
|
|
160
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
|
|
161
|
+
exclusive: false
|
|
167
162
|
});
|
|
168
|
-
let records = Object.values(await apiFetch({
|
|
169
|
-
path
|
|
170
|
-
})); // If we request fields but the result doesn't contain the fields,
|
|
171
|
-
// explicitely set these fields as "undefined"
|
|
172
|
-
// that way we consider the query "fullfilled".
|
|
173
|
-
|
|
174
|
-
if (query._fields) {
|
|
175
|
-
records = records.map(record => {
|
|
176
|
-
query._fields.split(',').forEach(field => {
|
|
177
|
-
if (!record.hasOwnProperty(field)) {
|
|
178
|
-
record[field] = undefined;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
163
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
164
|
+
try {
|
|
165
|
+
var _query;
|
|
185
166
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
});
|
|
198
|
-
dispatch({
|
|
199
|
-
type: 'FINISH_RESOLUTIONS',
|
|
200
|
-
selectorName: 'getEntityRecord',
|
|
201
|
-
args: resolutionsArgs
|
|
167
|
+
if (query._fields) {
|
|
168
|
+
// If requesting specific fields, items and query association to said
|
|
169
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
170
|
+
// the ID.
|
|
171
|
+
query = { ...query,
|
|
172
|
+
_fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const path = addQueryArgs(entity.baseURL, { ...entity.baseURLParams,
|
|
177
|
+
...query
|
|
202
178
|
});
|
|
179
|
+
let records = Object.values(await apiFetch({
|
|
180
|
+
path
|
|
181
|
+
})); // If we request fields but the result doesn't contain the fields,
|
|
182
|
+
// explicitely set these fields as "undefined"
|
|
183
|
+
// that way we consider the query "fullfilled".
|
|
184
|
+
|
|
185
|
+
if (query._fields) {
|
|
186
|
+
records = records.map(record => {
|
|
187
|
+
query._fields.split(',').forEach(field => {
|
|
188
|
+
if (!record.hasOwnProperty(field)) {
|
|
189
|
+
record[field] = undefined;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return record;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
198
|
+
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
199
|
+
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
200
|
+
|
|
201
|
+
if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
|
|
202
|
+
const key = entity.key || DEFAULT_ENTITY_KEY;
|
|
203
|
+
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
204
|
+
dispatch({
|
|
205
|
+
type: 'START_RESOLUTIONS',
|
|
206
|
+
selectorName: 'getEntityRecord',
|
|
207
|
+
args: resolutionsArgs
|
|
208
|
+
});
|
|
209
|
+
dispatch({
|
|
210
|
+
type: 'FINISH_RESOLUTIONS',
|
|
211
|
+
selectorName: 'getEntityRecord',
|
|
212
|
+
args: resolutionsArgs
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
} catch (error) {// We need a way to handle and access REST API errors in state
|
|
216
|
+
// Until then, catching the error ensures the resolver is marked as resolved.
|
|
217
|
+
// See similar implementation in `getEntityRecord()`.
|
|
218
|
+
} finally {
|
|
219
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
203
220
|
}
|
|
204
|
-
}
|
|
205
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
206
|
-
}
|
|
221
|
+
};
|
|
207
222
|
};
|
|
208
223
|
|
|
209
224
|
getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
@@ -214,10 +229,11 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
|
214
229
|
*/
|
|
215
230
|
|
|
216
231
|
|
|
217
|
-
export const getCurrentTheme = () => async
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
export const getCurrentTheme = () => async _ref5 => {
|
|
233
|
+
let {
|
|
234
|
+
dispatch,
|
|
235
|
+
resolveSelect
|
|
236
|
+
} = _ref5;
|
|
221
237
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
222
238
|
status: 'active'
|
|
223
239
|
});
|
|
@@ -234,9 +250,11 @@ export const getThemeSupports = forwardResolver('getCurrentTheme');
|
|
|
234
250
|
* @param {string} url URL to get the preview for.
|
|
235
251
|
*/
|
|
236
252
|
|
|
237
|
-
export const getEmbedPreview = url => async
|
|
238
|
-
|
|
239
|
-
|
|
253
|
+
export const getEmbedPreview = url => async _ref6 => {
|
|
254
|
+
let {
|
|
255
|
+
dispatch
|
|
256
|
+
} = _ref6;
|
|
257
|
+
|
|
240
258
|
try {
|
|
241
259
|
const embedProxyResponse = await apiFetch({
|
|
242
260
|
path: addQueryArgs('/oembed/1.0/proxy', {
|
|
@@ -259,9 +277,10 @@ export const getEmbedPreview = url => async ({
|
|
|
259
277
|
* @param {?string} id ID of the rest resource to check.
|
|
260
278
|
*/
|
|
261
279
|
|
|
262
|
-
export const canUser = (action, resource, id) => async
|
|
263
|
-
|
|
264
|
-
|
|
280
|
+
export const canUser = (action, resource, id) => async _ref7 => {
|
|
281
|
+
let {
|
|
282
|
+
dispatch
|
|
283
|
+
} = _ref7;
|
|
265
284
|
const methods = {
|
|
266
285
|
create: 'POST',
|
|
267
286
|
read: 'GET',
|
|
@@ -318,9 +337,10 @@ export const canUser = (action, resource, id) => async ({
|
|
|
318
337
|
* @param {string} recordId Record's id.
|
|
319
338
|
*/
|
|
320
339
|
|
|
321
|
-
export const canUserEditEntityRecord = (kind, name, recordId) => async
|
|
322
|
-
|
|
323
|
-
|
|
340
|
+
export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
|
|
341
|
+
let {
|
|
342
|
+
dispatch
|
|
343
|
+
} = _ref8;
|
|
324
344
|
const entities = await dispatch(getKindEntities(kind));
|
|
325
345
|
const entity = find(entities, {
|
|
326
346
|
kind,
|
|
@@ -341,10 +361,11 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
|
341
361
|
* @param {number} postId The id of the parent post.
|
|
342
362
|
*/
|
|
343
363
|
|
|
344
|
-
export const getAutosaves = (postType, postId) => async
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
364
|
+
export const getAutosaves = (postType, postId) => async _ref9 => {
|
|
365
|
+
let {
|
|
366
|
+
dispatch,
|
|
367
|
+
resolveSelect
|
|
368
|
+
} = _ref9;
|
|
348
369
|
const {
|
|
349
370
|
rest_base: restBase
|
|
350
371
|
} = await resolveSelect.getPostType(postType);
|
|
@@ -366,9 +387,10 @@ export const getAutosaves = (postType, postId) => async ({
|
|
|
366
387
|
* @param {number} postId The id of the parent post.
|
|
367
388
|
*/
|
|
368
389
|
|
|
369
|
-
export const getAutosave = (postType, postId) => async
|
|
370
|
-
|
|
371
|
-
|
|
390
|
+
export const getAutosave = (postType, postId) => async _ref10 => {
|
|
391
|
+
let {
|
|
392
|
+
resolveSelect
|
|
393
|
+
} = _ref10;
|
|
372
394
|
await resolveSelect.getAutosaves(postType, postId);
|
|
373
395
|
};
|
|
374
396
|
/**
|
|
@@ -377,10 +399,11 @@ export const getAutosave = (postType, postId) => async ({
|
|
|
377
399
|
* @param {string} link Link.
|
|
378
400
|
*/
|
|
379
401
|
|
|
380
|
-
export const __experimentalGetTemplateForLink = link => async
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
402
|
+
export const __experimentalGetTemplateForLink = link => async _ref11 => {
|
|
403
|
+
let {
|
|
404
|
+
dispatch,
|
|
405
|
+
resolveSelect
|
|
406
|
+
} = _ref11;
|
|
384
407
|
// Ideally this should be using an apiFetch call
|
|
385
408
|
// We could potentially do so by adding a "filter" to the `wp_template` end point.
|
|
386
409
|
// Also it seems the returned object is not a regular REST API post type.
|
|
@@ -389,9 +412,12 @@ export const __experimentalGetTemplateForLink = link => async ({
|
|
|
389
412
|
try {
|
|
390
413
|
template = await window.fetch(addQueryArgs(link, {
|
|
391
414
|
'_wp-find-template': true
|
|
392
|
-
})).then(res => res.json()).then(
|
|
393
|
-
|
|
394
|
-
|
|
415
|
+
})).then(res => res.json()).then(_ref12 => {
|
|
416
|
+
let {
|
|
417
|
+
data
|
|
418
|
+
} = _ref12;
|
|
419
|
+
return data;
|
|
420
|
+
});
|
|
395
421
|
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
396
422
|
}
|
|
397
423
|
|
|
@@ -412,10 +438,11 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
|
412
438
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
413
439
|
};
|
|
414
440
|
|
|
415
|
-
export const __experimentalGetCurrentGlobalStylesId = () => async
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
441
|
+
export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
442
|
+
let {
|
|
443
|
+
dispatch,
|
|
444
|
+
resolveSelect
|
|
445
|
+
} = _ref13;
|
|
419
446
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
420
447
|
status: 'active'
|
|
421
448
|
});
|
|
@@ -429,10 +456,11 @@ export const __experimentalGetCurrentGlobalStylesId = () => async ({
|
|
|
429
456
|
dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id);
|
|
430
457
|
}
|
|
431
458
|
};
|
|
432
|
-
export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
459
|
+
export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
|
|
460
|
+
let {
|
|
461
|
+
resolveSelect,
|
|
462
|
+
dispatch
|
|
463
|
+
} = _ref14;
|
|
436
464
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
437
465
|
const themeGlobalStyles = await apiFetch({
|
|
438
466
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","hasIn","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAKC,KAAF,IAAa,OAAQ;AAAEC,EAAAA;AAAF,CAAR,KAA0B;AAChE,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAA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IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAACxC,IAAP,KAAgB,UAFhB,IAGAwC,MAAM,CAACvC,IAAP,KAAgB,aAJjB;AAMA,CAPD;;AASA,OAAO,MAAM0F,sCAAsC,GAAG,MAAM,OAAQ;AACnEnG,EAAAA,QADmE;AAEnEmD,EAAAA;AAFmE,CAAR,KAGrD;AACN,QAAMC,YAAY,GAAG,MAAMD,aAAa,CAACnB,gBAAd,CAC1B,MAD0B,EAE1B,OAF0B,EAG1B;AAAEqB,IAAAA,MAAM,EAAE;AAAV,GAH0B,CAA3B;AAKA,QAAM+C,eAAe,GAAGjH,GAAG,CAAEiE,YAAF,EAAgB,CAC1C,CAD0C,EAE1C,QAF0C,EAG1C,uBAH0C,EAI1C,CAJ0C,EAK1C,MAL0C,CAAhB,CAA3B;;AAOA,MAAKgD,eAAL,EAAuB;AACtB,UAAMC,kBAAkB,GAAG,MAAM7G,QAAQ,CAAE;AAC1CiE,MAAAA,GAAG,EAAE2C;AADqC,KAAF,CAAzC;;AAGApG,IAAAA,QAAQ,CAACsG,0CAAT,CACCD,kBAAkB,CAACvC,EADpB;AAGA;AACD,CAxBM;AA0BP,OAAO,MAAMyC,6CAA6C,GAAG,MAAM,OAAQ;AAC1EpD,EAAAA,aAD0E;AAE1EnD,EAAAA;AAF0E,CAAR,KAG5D;AACN,QAAMwG,YAAY,GAAG,MAAMrD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAMuD,iBAAiB,GAAG,MAAMjH,QAAQ,CAAE;AACzCS,IAAAA,IAAI,EAAG,+BAA+BuG,YAAY,CAACE,UAAY;AADtB,GAAF,CAAxC;AAGA,QAAM1G,QAAQ,CAAC2G,0CAAT,CACLH,YAAY,CAACE,UADR,EAELD,iBAFK,CAAN;AAIA,CAZM","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + ( key ? '/' + key : '' ), {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme = () => async ( { dispatch, resolveSelect } ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId = () => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\tconst globalStylesURL = get( activeThemes, [\n\t\t0,\n\t\t'_links',\n\t\t'wp:user-global-styles',\n\t\t0,\n\t\t'href',\n\t] );\n\tif ( globalStylesURL ) {\n\t\tconst globalStylesObject = await apiFetch( {\n\t\t\turl: globalStylesURL,\n\t\t} );\n\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\tglobalStylesObject.id\n\t\t);\n\t}\n};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst themeGlobalStyles = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t} );\n\tawait dispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\tcurrentTheme.stylesheet,\n\t\tthemeGlobalStyles\n\t);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","hasIn","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAKC,KAAF,IAAa,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AAChE,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,GAAF,CAA5B;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CAPM;AASP;AACA;AACA;;AACA,OAAO,MAAME,cAAc,GAAG,MAAM,eAA0B;AAAA,MAAlB;AAAEJ,IAAAA;AAAF,GAAkB;AAC7D,QAAMK,WAAW,GAAG,MAAMb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J,IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAACxC,IAAP,KAAgB,UAFhB,IAGAwC,MAAM,CAACvC,IAAP,KAAgB,aAJjB;AAMA,CAPD;;AASA,OAAO,MAAM0F,sCAAsC,GAAG,MAAM,gBAGrD;AAAA,MAH6D;AACnEnG,IAAAA,QADmE;AAEnEmD,IAAAA;AAFmE,GAG7D;AACN,QAAMC,YAAY,GAAG,MAAMD,aAAa,CAACnB,gBAAd,CAC1B,MAD0B,EAE1B,OAF0B,EAG1B;AAAEqB,IAAAA,MAAM,EAAE;AAAV,GAH0B,CAA3B;AAKA,QAAM+C,eAAe,GAAGjH,GAAG,CAAEiE,YAAF,EAAgB,CAC1C,CAD0C,EAE1C,QAF0C,EAG1C,uBAH0C,EAI1C,CAJ0C,EAK1C,MAL0C,CAAhB,CAA3B;;AAOA,MAAKgD,eAAL,EAAuB;AACtB,UAAMC,kBAAkB,GAAG,MAAM7G,QAAQ,CAAE;AAC1CiE,MAAAA,GAAG,EAAE2C;AADqC,KAAF,CAAzC;;AAGApG,IAAAA,QAAQ,CAACsG,0CAAT,CACCD,kBAAkB,CAACvC,EADpB;AAGA;AACD,CAxBM;AA0BP,OAAO,MAAMyC,6CAA6C,GAAG,MAAM,gBAG5D;AAAA,MAHoE;AAC1EpD,IAAAA,aAD0E;AAE1EnD,IAAAA;AAF0E,GAGpE;AACN,QAAMwG,YAAY,GAAG,MAAMrD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAMuD,iBAAiB,GAAG,MAAMjH,QAAQ,CAAE;AACzCS,IAAAA,IAAI,EAAG,+BAA+BuG,YAAY,CAACE,UAAY;AADtB,GAAF,CAAxC;AAGA,QAAM1G,QAAQ,CAAC2G,0CAAT,CACLH,YAAY,CAACE,UADR,EAELD,iBAFK,CAAN;AAIA,CAZM","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + ( key ? '/' + key : '' ), {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecords()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecord()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme = () => async ( { dispatch, resolveSelect } ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId = () => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\tconst globalStylesURL = get( activeThemes, [\n\t\t0,\n\t\t'_links',\n\t\t'wp:user-global-styles',\n\t\t0,\n\t\t'href',\n\t] );\n\tif ( globalStylesURL ) {\n\t\tconst globalStylesObject = await apiFetch( {\n\t\t\turl: globalStylesURL,\n\t\t} );\n\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\tglobalStylesObject.id\n\t\t);\n\t}\n};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst themeGlobalStyles = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t} );\n\tawait dispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\tcurrentTheme.stylesheet,\n\t\tthemeGlobalStyles\n\t);\n};\n"]}
|
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @return {Function} Enhanced resolver.
|
|
7
7
|
*/
|
|
8
|
-
const forwardResolver = resolverName => (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const forwardResolver = resolverName => function () {
|
|
9
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
+
args[_key] = arguments[_key];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return async _ref => {
|
|
14
|
+
let {
|
|
15
|
+
resolveSelect
|
|
16
|
+
} = _ref;
|
|
17
|
+
await resolveSelect[resolverName](...args);
|
|
18
|
+
};
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
export default forwardResolver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/utils/forward-resolver.js"],"names":["forwardResolver","resolverName","args","resolveSelect"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAKC,YAAF,IAAoB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/utils/forward-resolver.js"],"names":["forwardResolver","resolverName","args","resolveSelect"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAKC,YAAF,IAAoB;AAAA,oCAAKC,IAAL;AAAKA,IAAAA,IAAL;AAAA;;AAAA,SAAe,cAEpD;AAAA,QAF4D;AAClEC,MAAAA;AADkE,KAE5D;AACN,UAAMA,aAAa,CAAEF,YAAF,CAAb,CAA+B,GAAGC,IAAlC,CAAN;AACA,GAJ2C;AAAA,CAA5C;;AAMA,eAAeF,eAAf","sourcesContent":["/**\n * Higher-order function which forward the resolution to another resolver with the same arguments.\n *\n * @param {string} resolverName forwarded resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst forwardResolver = ( resolverName ) => ( ...args ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect[ resolverName ]( ...args );\n};\n\nexport default forwardResolver;\n"]}
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @return {Function} Higher-order reducer.
|
|
8
8
|
*/
|
|
9
|
-
export const onSubKey = actionProperty => reducer => (
|
|
9
|
+
export const onSubKey = actionProperty => reducer => function () {
|
|
10
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
10
12
|
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
11
13
|
// where reducer is scoped by action shape.
|
|
12
14
|
const key = action[actionProperty];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAAKC,cAAF,IAAwBC,OAAF,IAAe,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAAKC,cAAF,IAAwBC,OAAF,IAAe,YAGxD;AAAA,MAFJC,KAEI,uEAFI,EAEJ;AAAA,MADJC,MACI;AACJ;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANG,CAQJ;AACA;;;AACA,QAAMI,YAAY,GAAGL,OAAO,CAAEC,KAAK,CAAEE,GAAF,CAAP,EAAgBD,MAAhB,CAA5B;;AACA,MAAKG,YAAY,KAAKJ,KAAK,CAAEE,GAAF,CAA3B,EAAqC;AACpC,WAAOF,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,GAAF,GAASE;AAFH,GAAP;AAIA,CAtBM;AAwBP,eAAeP,QAAf","sourcesContent":["/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param {string} actionProperty Action property by which to key object.\n *\n * @return {Function} Higher-order reducer.\n */\nexport const onSubKey = ( actionProperty ) => ( reducer ) => (\n\tstate = {},\n\taction\n) => {\n\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t// where reducer is scoped by action shape.\n\tconst key = action[ actionProperty ];\n\tif ( key === undefined ) {\n\t\treturn state;\n\t}\n\n\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t// reducer which returns undefined on a key which is not yet tracked.\n\tconst nextKeyState = reducer( state[ key ], action );\n\tif ( nextKeyState === state[ key ] ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ key ]: nextKeyState,\n\t};\n};\n\nexport default onSubKey;\n"]}
|