@wordpress/core-data 4.0.1-next.253d9b6e21.0 → 4.0.3
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/README.md +11 -3
- package/build/actions.js +124 -117
- package/build/actions.js.map +1 -1
- package/build/batch/default-processor.js +58 -27
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +24 -18
- package/build/entities.js.map +1 -1
- package/build/index.js +9 -17
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +17 -77
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +77 -0
- package/build/locks/engine.js.map +1 -0
- package/build/locks/reducer.js +1 -5
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +6 -6
- package/build/locks/selectors.js.map +1 -1
- package/build/queried-data/get-query-parts.js +9 -4
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/selectors.js +3 -9
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +1 -4
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +120 -91
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +31 -11
- package/build/selectors.js.map +1 -1
- package/build/utils/if-not-resolved.js +6 -21
- package/build/utils/if-not-resolved.js.map +1 -1
- package/build/utils/index.js +8 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +19 -0
- package/build/utils/is-raw-attribute.js.map +1 -0
- package/build-module/actions.js +106 -107
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/default-processor.js +57 -27
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +19 -14
- package/build-module/entities.js.map +1 -1
- package/build-module/index.js +10 -14
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +14 -68
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +66 -0
- package/build-module/locks/engine.js.map +1 -0
- package/build-module/locks/reducer.js +1 -2
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +4 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +9 -4
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/selectors.js +3 -9
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +1 -3
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +94 -74
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +30 -10
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/if-not-resolved.js +6 -19
- package/build-module/utils/if-not-resolved.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +12 -0
- package/build-module/utils/is-raw-attribute.js.map +1 -0
- package/package.json +11 -12
- package/src/actions.js +112 -189
- package/src/batch/default-processor.js +57 -26
- package/src/batch/test/default-processor.js +53 -26
- package/src/entities.js +15 -16
- package/src/index.js +7 -10
- package/src/locks/actions.js +10 -61
- package/src/locks/engine.js +43 -0
- package/src/locks/reducer.js +1 -3
- package/src/locks/selectors.js +4 -4
- package/src/locks/test/engine.js +135 -0
- package/src/locks/test/reducer.js +1 -1
- package/src/locks/test/selectors.js +105 -124
- package/src/queried-data/get-query-parts.js +11 -6
- package/src/queried-data/selectors.js +2 -9
- package/src/queried-data/test/get-query-parts.js +1 -1
- package/src/queried-data/test/selectors.js +1 -0
- package/src/reducer.js +0 -2
- package/src/resolvers.js +86 -106
- package/src/selectors.js +113 -40
- package/src/test/actions.js +243 -172
- package/src/test/entities.js +40 -26
- package/src/test/resolvers.js +270 -223
- package/src/test/selectors.js +71 -0
- package/src/utils/if-not-resolved.js +8 -26
- package/src/utils/index.js +1 -0
- package/src/utils/is-raw-attribute.js +11 -0
- package/src/utils/test/if-not-resolved.js +28 -27
- package/src/utils/test/is-raw-attribute.js +22 -0
- package/build/controls.js +0 -44
- package/build/controls.js.map +0 -1
- package/build/locks/index.js +0 -47
- package/build/locks/index.js.map +0 -1
- package/build-module/controls.js +0 -31
- package/build-module/controls.js.map +0 -1
- package/build-module/locks/index.js +0 -4
- package/build-module/locks/index.js.map +0 -1
- package/src/controls.js +0 -31
- package/src/locks/index.js +0 -3
- package/src/locks/test/actions.js +0 -307
- package/src/test/integration.js +0 -264
package/build-module/actions.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { castArray,
|
|
4
|
+
import { castArray, isEqual, find } from 'lodash';
|
|
5
5
|
import { v4 as uuid } from 'uuid';
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
import { apiFetch, __unstableAwaitPromise } from '@wordpress/data-controls';
|
|
10
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
12
11
|
import { addQueryArgs } from '@wordpress/url';
|
|
13
12
|
/**
|
|
14
13
|
* Internal dependencies
|
|
@@ -16,9 +15,7 @@ import { addQueryArgs } from '@wordpress/url';
|
|
|
16
15
|
|
|
17
16
|
import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
|
|
18
17
|
import { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';
|
|
19
|
-
import { __unstableAcquireStoreLock, __unstableReleaseStoreLock } from './locks';
|
|
20
18
|
import { createBatch } from './batch';
|
|
21
|
-
import { getDispatch } from './controls';
|
|
22
19
|
import { STORE_NAME } from './name';
|
|
23
20
|
/**
|
|
24
21
|
* Returns an action object used in signalling that authors have been received.
|
|
@@ -155,13 +152,15 @@ export function receiveEmbedPreview(url, preview) {
|
|
|
155
152
|
* @param {Object} [options] Delete options.
|
|
156
153
|
* @param {Function} [options.__unstableFetch] Internal use only. Function to
|
|
157
154
|
* call instead of `apiFetch()`.
|
|
158
|
-
* Must return a
|
|
155
|
+
* Must return a promise.
|
|
159
156
|
*/
|
|
160
157
|
|
|
161
|
-
export
|
|
162
|
-
__unstableFetch =
|
|
163
|
-
} = {}) {
|
|
164
|
-
|
|
158
|
+
export const deleteEntityRecord = (kind, name, recordId, query, {
|
|
159
|
+
__unstableFetch = apiFetch
|
|
160
|
+
} = {}) => async ({
|
|
161
|
+
dispatch
|
|
162
|
+
}) => {
|
|
163
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
165
164
|
const entity = find(entities, {
|
|
166
165
|
kind,
|
|
167
166
|
name
|
|
@@ -169,21 +168,21 @@ export function* deleteEntityRecord(kind, name, recordId, query, {
|
|
|
169
168
|
let error;
|
|
170
169
|
let deletedRecord = false;
|
|
171
170
|
|
|
172
|
-
if (!entity) {
|
|
171
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
const lock =
|
|
175
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId], {
|
|
177
176
|
exclusive: true
|
|
178
177
|
});
|
|
179
178
|
|
|
180
179
|
try {
|
|
181
|
-
|
|
180
|
+
dispatch({
|
|
182
181
|
type: 'DELETE_ENTITY_RECORD_START',
|
|
183
182
|
kind,
|
|
184
183
|
name,
|
|
185
184
|
recordId
|
|
186
|
-
};
|
|
185
|
+
});
|
|
187
186
|
|
|
188
187
|
try {
|
|
189
188
|
let path = `${entity.baseURL}/${recordId}`;
|
|
@@ -192,34 +191,27 @@ export function* deleteEntityRecord(kind, name, recordId, query, {
|
|
|
192
191
|
path = addQueryArgs(path, query);
|
|
193
192
|
}
|
|
194
193
|
|
|
195
|
-
|
|
194
|
+
deletedRecord = await __unstableFetch({
|
|
196
195
|
path,
|
|
197
196
|
method: 'DELETE'
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
if (__unstableFetch) {
|
|
201
|
-
deletedRecord = yield __unstableAwaitPromise(__unstableFetch(options));
|
|
202
|
-
} else {
|
|
203
|
-
deletedRecord = yield apiFetch(options);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
yield removeItems(kind, name, recordId, true);
|
|
197
|
+
});
|
|
198
|
+
await dispatch(removeItems(kind, name, recordId, true));
|
|
207
199
|
} catch (_error) {
|
|
208
200
|
error = _error;
|
|
209
201
|
}
|
|
210
202
|
|
|
211
|
-
|
|
203
|
+
dispatch({
|
|
212
204
|
type: 'DELETE_ENTITY_RECORD_FINISH',
|
|
213
205
|
kind,
|
|
214
206
|
name,
|
|
215
207
|
recordId,
|
|
216
208
|
error
|
|
217
|
-
};
|
|
209
|
+
});
|
|
218
210
|
return deletedRecord;
|
|
219
211
|
} finally {
|
|
220
|
-
|
|
212
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
221
213
|
}
|
|
222
|
-
}
|
|
214
|
+
};
|
|
223
215
|
/**
|
|
224
216
|
* Returns an action object that triggers an
|
|
225
217
|
* edit to an entity record.
|
|
@@ -234,8 +226,11 @@ export function* deleteEntityRecord(kind, name, recordId, query, {
|
|
|
234
226
|
* @return {Object} Action object.
|
|
235
227
|
*/
|
|
236
228
|
|
|
237
|
-
export
|
|
238
|
-
|
|
229
|
+
export const editEntityRecord = (kind, name, recordId, edits, options = {}) => ({
|
|
230
|
+
select,
|
|
231
|
+
dispatch
|
|
232
|
+
}) => {
|
|
233
|
+
const entity = select.getEntity(kind, name);
|
|
239
234
|
|
|
240
235
|
if (!entity) {
|
|
241
236
|
throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
|
|
@@ -245,8 +240,8 @@ export function* editEntityRecord(kind, name, recordId, edits, options = {}) {
|
|
|
245
240
|
transientEdits = {},
|
|
246
241
|
mergedEdits = {}
|
|
247
242
|
} = entity;
|
|
248
|
-
const record =
|
|
249
|
-
const editedRecord =
|
|
243
|
+
const record = select.getRawEntityRecord(kind, name, recordId);
|
|
244
|
+
const editedRecord = select.getEditedEntityRecord(kind, name, recordId);
|
|
250
245
|
const edit = {
|
|
251
246
|
kind,
|
|
252
247
|
name,
|
|
@@ -264,7 +259,7 @@ export function* editEntityRecord(kind, name, recordId, edits, options = {}) {
|
|
|
264
259
|
}, {}),
|
|
265
260
|
transientEdits
|
|
266
261
|
};
|
|
267
|
-
|
|
262
|
+
dispatch({
|
|
268
263
|
type: 'EDIT_ENTITY_RECORD',
|
|
269
264
|
...edit,
|
|
270
265
|
meta: {
|
|
@@ -276,48 +271,58 @@ export function* editEntityRecord(kind, name, recordId, edits, options = {}) {
|
|
|
276
271
|
}, {})
|
|
277
272
|
}
|
|
278
273
|
}
|
|
279
|
-
};
|
|
280
|
-
}
|
|
274
|
+
});
|
|
275
|
+
};
|
|
281
276
|
/**
|
|
282
277
|
* Action triggered to undo the last edit to
|
|
283
278
|
* an entity record, if any.
|
|
279
|
+
*
|
|
280
|
+
* @return {undefined}
|
|
284
281
|
*/
|
|
285
282
|
|
|
286
|
-
export
|
|
287
|
-
|
|
283
|
+
export const undo = () => ({
|
|
284
|
+
select,
|
|
285
|
+
dispatch
|
|
286
|
+
}) => {
|
|
287
|
+
const undoEdit = select.getUndoEdit();
|
|
288
288
|
|
|
289
289
|
if (!undoEdit) {
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
|
|
293
|
+
dispatch({
|
|
294
294
|
type: 'EDIT_ENTITY_RECORD',
|
|
295
295
|
...undoEdit,
|
|
296
296
|
meta: {
|
|
297
297
|
isUndo: true
|
|
298
298
|
}
|
|
299
|
-
};
|
|
300
|
-
}
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
301
|
/**
|
|
302
302
|
* Action triggered to redo the last undoed
|
|
303
303
|
* edit to an entity record, if any.
|
|
304
|
+
*
|
|
305
|
+
* @return {undefined}
|
|
304
306
|
*/
|
|
305
307
|
|
|
306
|
-
export
|
|
307
|
-
|
|
308
|
+
export const redo = () => ({
|
|
309
|
+
select,
|
|
310
|
+
dispatch
|
|
311
|
+
}) => {
|
|
312
|
+
const redoEdit = select.getRedoEdit();
|
|
308
313
|
|
|
309
314
|
if (!redoEdit) {
|
|
310
315
|
return;
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
|
|
318
|
+
dispatch({
|
|
314
319
|
type: 'EDIT_ENTITY_RECORD',
|
|
315
320
|
...redoEdit,
|
|
316
321
|
meta: {
|
|
317
322
|
isRedo: true
|
|
318
323
|
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
324
|
+
});
|
|
325
|
+
};
|
|
321
326
|
/**
|
|
322
327
|
* Forces the creation of a new undo level.
|
|
323
328
|
*
|
|
@@ -339,27 +344,30 @@ export function __unstableCreateUndoLevel() {
|
|
|
339
344
|
* @param {boolean} [options.isAutosave=false] Whether this is an autosave.
|
|
340
345
|
* @param {Function} [options.__unstableFetch] Internal use only. Function to
|
|
341
346
|
* call instead of `apiFetch()`.
|
|
342
|
-
* Must return a
|
|
343
|
-
* descriptor.
|
|
347
|
+
* Must return a promise.
|
|
344
348
|
*/
|
|
345
349
|
|
|
346
|
-
export
|
|
350
|
+
export const saveEntityRecord = (kind, name, record, {
|
|
347
351
|
isAutosave = false,
|
|
348
|
-
__unstableFetch =
|
|
349
|
-
} = {}) {
|
|
350
|
-
|
|
352
|
+
__unstableFetch = apiFetch
|
|
353
|
+
} = {}) => async ({
|
|
354
|
+
select,
|
|
355
|
+
resolveSelect,
|
|
356
|
+
dispatch
|
|
357
|
+
}) => {
|
|
358
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
351
359
|
const entity = find(entities, {
|
|
352
360
|
kind,
|
|
353
361
|
name
|
|
354
362
|
});
|
|
355
363
|
|
|
356
|
-
if (!entity) {
|
|
364
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
357
365
|
return;
|
|
358
366
|
}
|
|
359
367
|
|
|
360
368
|
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
|
|
361
369
|
const recordId = record[entityIdKey];
|
|
362
|
-
const lock =
|
|
370
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId || uuid()], {
|
|
363
371
|
exclusive: true
|
|
364
372
|
});
|
|
365
373
|
|
|
@@ -368,8 +376,8 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
368
376
|
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
|
|
369
377
|
for (const [key, value] of Object.entries(record)) {
|
|
370
378
|
if (typeof value === 'function') {
|
|
371
|
-
const evaluatedValue = value(
|
|
372
|
-
|
|
379
|
+
const evaluatedValue = value(select.getEditedEntityRecord(kind, name, recordId));
|
|
380
|
+
dispatch.editEntityRecord(kind, name, recordId, {
|
|
373
381
|
[key]: evaluatedValue
|
|
374
382
|
}, {
|
|
375
383
|
undoIgnore: true
|
|
@@ -378,28 +386,28 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
378
386
|
}
|
|
379
387
|
}
|
|
380
388
|
|
|
381
|
-
|
|
389
|
+
dispatch({
|
|
382
390
|
type: 'SAVE_ENTITY_RECORD_START',
|
|
383
391
|
kind,
|
|
384
392
|
name,
|
|
385
393
|
recordId,
|
|
386
394
|
isAutosave
|
|
387
|
-
};
|
|
395
|
+
});
|
|
388
396
|
let updatedRecord;
|
|
389
397
|
let error;
|
|
390
398
|
|
|
391
399
|
try {
|
|
392
400
|
const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`;
|
|
393
|
-
const persistedRecord =
|
|
401
|
+
const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
|
|
394
402
|
|
|
395
403
|
if (isAutosave) {
|
|
396
404
|
// Most of this autosave logic is very specific to posts.
|
|
397
405
|
// This is fine for now as it is the only supported autosave,
|
|
398
406
|
// but ideally this should all be handled in the back end,
|
|
399
407
|
// so the client just sends and receives objects.
|
|
400
|
-
const currentUser =
|
|
408
|
+
const currentUser = select.getCurrentUser();
|
|
401
409
|
const currentUserId = currentUser ? currentUser.id : undefined;
|
|
402
|
-
const autosavePost =
|
|
410
|
+
const autosavePost = resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
|
|
403
411
|
// So we fallback to the previous autosave and then
|
|
404
412
|
// to the actual persisted entity if the edits don't
|
|
405
413
|
// have a value.
|
|
@@ -410,29 +418,21 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
410
418
|
};
|
|
411
419
|
data = Object.keys(data).reduce((acc, key) => {
|
|
412
420
|
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
413
|
-
|
|
414
|
-
acc[key] = get(data[key], 'raw', data[key]);
|
|
421
|
+
acc[key] = data[key];
|
|
415
422
|
}
|
|
416
423
|
|
|
417
424
|
return acc;
|
|
418
425
|
}, {
|
|
419
426
|
status: data.status === 'auto-draft' ? 'draft' : data.status
|
|
420
427
|
});
|
|
421
|
-
|
|
428
|
+
updatedRecord = await __unstableFetch({
|
|
422
429
|
path: `${path}/autosaves`,
|
|
423
430
|
method: 'POST',
|
|
424
431
|
data
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
if (__unstableFetch) {
|
|
428
|
-
updatedRecord = yield __unstableAwaitPromise(__unstableFetch(options));
|
|
429
|
-
} else {
|
|
430
|
-
updatedRecord = yield apiFetch(options);
|
|
431
|
-
} // An autosave may be processed by the server as a regular save
|
|
432
|
+
}); // An autosave may be processed by the server as a regular save
|
|
432
433
|
// when its update is requested by the author and the post had
|
|
433
434
|
// draft or auto-draft status.
|
|
434
435
|
|
|
435
|
-
|
|
436
436
|
if (persistedRecord.id === updatedRecord.id) {
|
|
437
437
|
let newRecord = { ...persistedRecord,
|
|
438
438
|
...data,
|
|
@@ -441,22 +441,21 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
441
441
|
newRecord = Object.keys(newRecord).reduce((acc, key) => {
|
|
442
442
|
// These properties are persisted in autosaves.
|
|
443
443
|
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
444
|
-
|
|
445
|
-
acc[key] = get(newRecord[key], 'raw', newRecord[key]);
|
|
444
|
+
acc[key] = newRecord[key];
|
|
446
445
|
} else if (key === 'status') {
|
|
447
446
|
// Status is only persisted in autosaves when going from
|
|
448
447
|
// "auto-draft" to "draft".
|
|
449
448
|
acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
|
|
450
449
|
} else {
|
|
451
450
|
// These properties are not persisted in autosaves.
|
|
452
|
-
acc[key] =
|
|
451
|
+
acc[key] = persistedRecord[key];
|
|
453
452
|
}
|
|
454
453
|
|
|
455
454
|
return acc;
|
|
456
455
|
}, {});
|
|
457
|
-
|
|
456
|
+
dispatch.receiveEntityRecords(kind, name, newRecord, undefined, true);
|
|
458
457
|
} else {
|
|
459
|
-
|
|
458
|
+
dispatch.receiveAutosaves(persistedRecord.id, updatedRecord);
|
|
460
459
|
}
|
|
461
460
|
} else {
|
|
462
461
|
let edits = record;
|
|
@@ -467,37 +466,30 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
467
466
|
};
|
|
468
467
|
}
|
|
469
468
|
|
|
470
|
-
|
|
469
|
+
updatedRecord = await __unstableFetch({
|
|
471
470
|
path,
|
|
472
471
|
method: recordId ? 'PUT' : 'POST',
|
|
473
472
|
data: edits
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
if (__unstableFetch) {
|
|
477
|
-
updatedRecord = yield __unstableAwaitPromise(__unstableFetch(options));
|
|
478
|
-
} else {
|
|
479
|
-
updatedRecord = yield apiFetch(options);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
yield receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
|
|
473
|
+
});
|
|
474
|
+
dispatch.receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
|
|
483
475
|
}
|
|
484
476
|
} catch (_error) {
|
|
485
477
|
error = _error;
|
|
486
478
|
}
|
|
487
479
|
|
|
488
|
-
|
|
480
|
+
dispatch({
|
|
489
481
|
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
490
482
|
kind,
|
|
491
483
|
name,
|
|
492
484
|
recordId,
|
|
493
485
|
error,
|
|
494
486
|
isAutosave
|
|
495
|
-
};
|
|
487
|
+
});
|
|
496
488
|
return updatedRecord;
|
|
497
489
|
} finally {
|
|
498
|
-
|
|
490
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
499
491
|
}
|
|
500
|
-
}
|
|
492
|
+
};
|
|
501
493
|
/**
|
|
502
494
|
* Runs multiple core-data actions at the same time using one API request.
|
|
503
495
|
*
|
|
@@ -521,33 +513,34 @@ export function* saveEntityRecord(kind, name, record, {
|
|
|
521
513
|
* values of each function given in `requests`.
|
|
522
514
|
*/
|
|
523
515
|
|
|
524
|
-
export
|
|
516
|
+
export const __experimentalBatch = requests => async ({
|
|
517
|
+
dispatch
|
|
518
|
+
}) => {
|
|
525
519
|
const batch = createBatch();
|
|
526
|
-
const dispatch = yield getDispatch();
|
|
527
520
|
const api = {
|
|
528
521
|
saveEntityRecord(kind, name, record, options) {
|
|
529
|
-
return batch.add(add => dispatch
|
|
522
|
+
return batch.add(add => dispatch.saveEntityRecord(kind, name, record, { ...options,
|
|
530
523
|
__unstableFetch: add
|
|
531
524
|
}));
|
|
532
525
|
},
|
|
533
526
|
|
|
534
527
|
saveEditedEntityRecord(kind, name, recordId, options) {
|
|
535
|
-
return batch.add(add => dispatch
|
|
528
|
+
return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, { ...options,
|
|
536
529
|
__unstableFetch: add
|
|
537
530
|
}));
|
|
538
531
|
},
|
|
539
532
|
|
|
540
533
|
deleteEntityRecord(kind, name, recordId, query, options) {
|
|
541
|
-
return batch.add(add => dispatch
|
|
534
|
+
return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, { ...options,
|
|
542
535
|
__unstableFetch: add
|
|
543
536
|
}));
|
|
544
537
|
}
|
|
545
538
|
|
|
546
539
|
};
|
|
547
540
|
const resultPromises = requests.map(request => request(api));
|
|
548
|
-
const [, ...results] =
|
|
541
|
+
const [, ...results] = await Promise.all([batch.run(), ...resultPromises]);
|
|
549
542
|
return results;
|
|
550
|
-
}
|
|
543
|
+
};
|
|
551
544
|
/**
|
|
552
545
|
* Action triggered to save an entity record's edits.
|
|
553
546
|
*
|
|
@@ -557,18 +550,21 @@ export function* __experimentalBatch(requests) {
|
|
|
557
550
|
* @param {Object} options Saving options.
|
|
558
551
|
*/
|
|
559
552
|
|
|
560
|
-
export
|
|
561
|
-
|
|
553
|
+
export const saveEditedEntityRecord = (kind, name, recordId, options) => async ({
|
|
554
|
+
select,
|
|
555
|
+
dispatch
|
|
556
|
+
}) => {
|
|
557
|
+
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
|
562
558
|
return;
|
|
563
559
|
}
|
|
564
560
|
|
|
565
|
-
const edits =
|
|
561
|
+
const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
|
|
566
562
|
const record = {
|
|
567
563
|
id: recordId,
|
|
568
564
|
...edits
|
|
569
565
|
};
|
|
570
|
-
return
|
|
571
|
-
}
|
|
566
|
+
return await dispatch.saveEntityRecord(kind, name, record, options);
|
|
567
|
+
};
|
|
572
568
|
/**
|
|
573
569
|
* Action triggered to save only specified properties for the entity.
|
|
574
570
|
*
|
|
@@ -579,12 +575,15 @@ export function* saveEditedEntityRecord(kind, name, recordId, options) {
|
|
|
579
575
|
* @param {Object} options Saving options.
|
|
580
576
|
*/
|
|
581
577
|
|
|
582
|
-
export
|
|
583
|
-
|
|
578
|
+
export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({
|
|
579
|
+
select,
|
|
580
|
+
dispatch
|
|
581
|
+
}) => {
|
|
582
|
+
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
|
584
583
|
return;
|
|
585
584
|
}
|
|
586
585
|
|
|
587
|
-
const edits =
|
|
586
|
+
const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
|
|
588
587
|
const editsToSave = {};
|
|
589
588
|
|
|
590
589
|
for (const edit in edits) {
|
|
@@ -593,8 +592,8 @@ export function* __experimentalSaveSpecifiedEntityEdits(kind, name, recordId, it
|
|
|
593
592
|
}
|
|
594
593
|
}
|
|
595
594
|
|
|
596
|
-
return
|
|
597
|
-
}
|
|
595
|
+
return await dispatch.saveEntityRecord(kind, name, editsToSave, options);
|
|
596
|
+
};
|
|
598
597
|
/**
|
|
599
598
|
* Returns an action object used in signalling that Upload permissions have been received.
|
|
600
599
|
*
|