@wordpress/core-data 4.0.5 → 4.0.10-next.33ec3857e2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- 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 +31 -36
- 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/selectors.js +2 -15
- package/build-module/selectors.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/selectors.js +2 -15
- package/src/test/actions.js +2 -2
- package/src/test/selectors.js +4 -4
package/build-module/actions.js
CHANGED
|
@@ -74,7 +74,10 @@ export function addEntities(entities) {
|
|
|
74
74
|
* @return {Object} Action object.
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
|
-
export function receiveEntityRecords(kind, name, records, query
|
|
77
|
+
export function receiveEntityRecords(kind, name, records, query) {
|
|
78
|
+
let invalidateCache = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
79
|
+
let edits = arguments.length > 5 ? arguments[5] : undefined;
|
|
80
|
+
|
|
78
81
|
// Auto drafts should not have titles, but some plugins rely on them so we can't filter this
|
|
79
82
|
// on the server.
|
|
80
83
|
if (kind === 'postType') {
|
|
@@ -188,62 +191,66 @@ export function receiveEmbedPreview(url, preview) {
|
|
|
188
191
|
* Must return a promise.
|
|
189
192
|
*/
|
|
190
193
|
|
|
191
|
-
export const deleteEntityRecord = (kind, name, recordId, query
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
194
|
+
export const deleteEntityRecord = function (kind, name, recordId, query) {
|
|
195
|
+
let {
|
|
196
|
+
__unstableFetch = apiFetch
|
|
197
|
+
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
198
|
+
return async _ref => {
|
|
199
|
+
let {
|
|
200
|
+
dispatch
|
|
201
|
+
} = _ref;
|
|
202
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
203
|
+
const entity = find(entities, {
|
|
204
|
+
kind,
|
|
205
|
+
name
|
|
206
|
+
});
|
|
207
|
+
let error;
|
|
208
|
+
let deletedRecord = false;
|
|
207
209
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
211
213
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
type: 'DELETE_ENTITY_RECORD_START',
|
|
215
|
-
kind,
|
|
216
|
-
name,
|
|
217
|
-
recordId
|
|
214
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId], {
|
|
215
|
+
exclusive: true
|
|
218
216
|
});
|
|
219
217
|
|
|
220
218
|
try {
|
|
221
|
-
|
|
219
|
+
dispatch({
|
|
220
|
+
type: 'DELETE_ENTITY_RECORD_START',
|
|
221
|
+
kind,
|
|
222
|
+
name,
|
|
223
|
+
recordId
|
|
224
|
+
});
|
|
222
225
|
|
|
223
|
-
|
|
224
|
-
path =
|
|
226
|
+
try {
|
|
227
|
+
let path = `${entity.baseURL}/${recordId}`;
|
|
228
|
+
|
|
229
|
+
if (query) {
|
|
230
|
+
path = addQueryArgs(path, query);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
deletedRecord = await __unstableFetch({
|
|
234
|
+
path,
|
|
235
|
+
method: 'DELETE'
|
|
236
|
+
});
|
|
237
|
+
await dispatch(removeItems(kind, name, recordId, true));
|
|
238
|
+
} catch (_error) {
|
|
239
|
+
error = _error;
|
|
225
240
|
}
|
|
226
241
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
dispatch({
|
|
243
|
+
type: 'DELETE_ENTITY_RECORD_FINISH',
|
|
244
|
+
kind,
|
|
245
|
+
name,
|
|
246
|
+
recordId,
|
|
247
|
+
error
|
|
230
248
|
});
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
249
|
+
return deletedRecord;
|
|
250
|
+
} finally {
|
|
251
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
234
252
|
}
|
|
235
|
-
|
|
236
|
-
dispatch({
|
|
237
|
-
type: 'DELETE_ENTITY_RECORD_FINISH',
|
|
238
|
-
kind,
|
|
239
|
-
name,
|
|
240
|
-
recordId,
|
|
241
|
-
error
|
|
242
|
-
});
|
|
243
|
-
return deletedRecord;
|
|
244
|
-
} finally {
|
|
245
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
246
|
-
}
|
|
253
|
+
};
|
|
247
254
|
};
|
|
248
255
|
/**
|
|
249
256
|
* Returns an action object that triggers an
|
|
@@ -259,52 +266,56 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
|
|
|
259
266
|
* @return {Object} Action object.
|
|
260
267
|
*/
|
|
261
268
|
|
|
262
|
-
export const editEntityRecord = (kind, name, recordId, edits
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
export const editEntityRecord = function (kind, name, recordId, edits) {
|
|
270
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
271
|
+
return _ref2 => {
|
|
272
|
+
let {
|
|
273
|
+
select,
|
|
274
|
+
dispatch
|
|
275
|
+
} = _ref2;
|
|
276
|
+
const entity = select.getEntity(kind, name);
|
|
277
|
+
|
|
278
|
+
if (!entity) {
|
|
279
|
+
throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
|
|
280
|
+
}
|
|
271
281
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
282
|
+
const {
|
|
283
|
+
transientEdits = {},
|
|
284
|
+
mergedEdits = {}
|
|
285
|
+
} = entity;
|
|
286
|
+
const record = select.getRawEntityRecord(kind, name, recordId);
|
|
287
|
+
const editedRecord = select.getEditedEntityRecord(kind, name, recordId);
|
|
288
|
+
const edit = {
|
|
289
|
+
kind,
|
|
290
|
+
name,
|
|
291
|
+
recordId,
|
|
292
|
+
// Clear edits when they are equal to their persisted counterparts
|
|
293
|
+
// so that the property is not considered dirty.
|
|
294
|
+
edits: Object.keys(edits).reduce((acc, key) => {
|
|
295
|
+
const recordValue = record[key];
|
|
296
|
+
const editedRecordValue = editedRecord[key];
|
|
297
|
+
const value = mergedEdits[key] ? { ...editedRecordValue,
|
|
298
|
+
...edits[key]
|
|
299
|
+
} : edits[key];
|
|
300
|
+
acc[key] = isEqual(recordValue, value) ? undefined : value;
|
|
301
|
+
return acc;
|
|
302
|
+
}, {}),
|
|
303
|
+
transientEdits
|
|
304
|
+
};
|
|
305
|
+
dispatch({
|
|
306
|
+
type: 'EDIT_ENTITY_RECORD',
|
|
307
|
+
...edit,
|
|
308
|
+
meta: {
|
|
309
|
+
undo: !options.undoIgnore && { ...edit,
|
|
310
|
+
// Send the current values for things like the first undo stack entry.
|
|
311
|
+
edits: Object.keys(edits).reduce((acc, key) => {
|
|
312
|
+
acc[key] = editedRecord[key];
|
|
313
|
+
return acc;
|
|
314
|
+
}, {})
|
|
315
|
+
}
|
|
305
316
|
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
317
|
+
});
|
|
318
|
+
};
|
|
308
319
|
};
|
|
309
320
|
/**
|
|
310
321
|
* Action triggered to undo the last edit to
|
|
@@ -313,10 +324,11 @@ export const editEntityRecord = (kind, name, recordId, edits, options = {}) => (
|
|
|
313
324
|
* @return {undefined}
|
|
314
325
|
*/
|
|
315
326
|
|
|
316
|
-
export const undo = () =>
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
export const undo = () => _ref3 => {
|
|
328
|
+
let {
|
|
329
|
+
select,
|
|
330
|
+
dispatch
|
|
331
|
+
} = _ref3;
|
|
320
332
|
const undoEdit = select.getUndoEdit();
|
|
321
333
|
|
|
322
334
|
if (!undoEdit) {
|
|
@@ -338,10 +350,11 @@ export const undo = () => ({
|
|
|
338
350
|
* @return {undefined}
|
|
339
351
|
*/
|
|
340
352
|
|
|
341
|
-
export const redo = () =>
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
export const redo = () => _ref4 => {
|
|
354
|
+
let {
|
|
355
|
+
select,
|
|
356
|
+
dispatch
|
|
357
|
+
} = _ref4;
|
|
345
358
|
const redoEdit = select.getRedoEdit();
|
|
346
359
|
|
|
347
360
|
if (!redoEdit) {
|
|
@@ -380,148 +393,152 @@ export function __unstableCreateUndoLevel() {
|
|
|
380
393
|
* Must return a promise.
|
|
381
394
|
*/
|
|
382
395
|
|
|
383
|
-
export const saveEntityRecord = (kind, name, record
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
|
|
402
|
-
const recordId = record[entityIdKey];
|
|
403
|
-
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId || uuid()], {
|
|
404
|
-
exclusive: true
|
|
405
|
-
});
|
|
396
|
+
export const saveEntityRecord = function (kind, name, record) {
|
|
397
|
+
let {
|
|
398
|
+
isAutosave = false,
|
|
399
|
+
__unstableFetch = apiFetch
|
|
400
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
401
|
+
return async _ref5 => {
|
|
402
|
+
let {
|
|
403
|
+
select,
|
|
404
|
+
resolveSelect,
|
|
405
|
+
dispatch
|
|
406
|
+
} = _ref5;
|
|
407
|
+
const entities = await dispatch(getKindEntities(kind));
|
|
408
|
+
const entity = find(entities, {
|
|
409
|
+
kind,
|
|
410
|
+
name
|
|
411
|
+
});
|
|
406
412
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
|
|
410
|
-
for (const [key, value] of Object.entries(record)) {
|
|
411
|
-
if (typeof value === 'function') {
|
|
412
|
-
const evaluatedValue = value(select.getEditedEntityRecord(kind, name, recordId));
|
|
413
|
-
dispatch.editEntityRecord(kind, name, recordId, {
|
|
414
|
-
[key]: evaluatedValue
|
|
415
|
-
}, {
|
|
416
|
-
undoIgnore: true
|
|
417
|
-
});
|
|
418
|
-
record[key] = evaluatedValue;
|
|
419
|
-
}
|
|
413
|
+
if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
|
|
414
|
+
return;
|
|
420
415
|
}
|
|
421
416
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
recordId,
|
|
427
|
-
isAutosave
|
|
417
|
+
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
|
|
418
|
+
const recordId = record[entityIdKey];
|
|
419
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId || uuid()], {
|
|
420
|
+
exclusive: true
|
|
428
421
|
});
|
|
429
|
-
let updatedRecord;
|
|
430
|
-
let error;
|
|
431
422
|
|
|
432
423
|
try {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
// have a value.
|
|
447
|
-
|
|
448
|
-
let data = { ...persistedRecord,
|
|
449
|
-
...autosavePost,
|
|
450
|
-
...record
|
|
451
|
-
};
|
|
452
|
-
data = Object.keys(data).reduce((acc, key) => {
|
|
453
|
-
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
454
|
-
acc[key] = data[key];
|
|
455
|
-
}
|
|
424
|
+
// Evaluate optimized edits.
|
|
425
|
+
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
|
|
426
|
+
for (const [key, value] of Object.entries(record)) {
|
|
427
|
+
if (typeof value === 'function') {
|
|
428
|
+
const evaluatedValue = value(select.getEditedEntityRecord(kind, name, recordId));
|
|
429
|
+
dispatch.editEntityRecord(kind, name, recordId, {
|
|
430
|
+
[key]: evaluatedValue
|
|
431
|
+
}, {
|
|
432
|
+
undoIgnore: true
|
|
433
|
+
});
|
|
434
|
+
record[key] = evaluatedValue;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
456
437
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
438
|
+
dispatch({
|
|
439
|
+
type: 'SAVE_ENTITY_RECORD_START',
|
|
440
|
+
kind,
|
|
441
|
+
name,
|
|
442
|
+
recordId,
|
|
443
|
+
isAutosave
|
|
444
|
+
});
|
|
445
|
+
let updatedRecord;
|
|
446
|
+
let error;
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`;
|
|
450
|
+
const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
|
|
451
|
+
|
|
452
|
+
if (isAutosave) {
|
|
453
|
+
// Most of this autosave logic is very specific to posts.
|
|
454
|
+
// This is fine for now as it is the only supported autosave,
|
|
455
|
+
// but ideally this should all be handled in the back end,
|
|
456
|
+
// so the client just sends and receives objects.
|
|
457
|
+
const currentUser = select.getCurrentUser();
|
|
458
|
+
const currentUserId = currentUser ? currentUser.id : undefined;
|
|
459
|
+
const autosavePost = resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
|
|
460
|
+
// So we fallback to the previous autosave and then
|
|
461
|
+
// to the actual persisted entity if the edits don't
|
|
462
|
+
// have a value.
|
|
463
|
+
|
|
464
|
+
let data = { ...persistedRecord,
|
|
465
|
+
...autosavePost,
|
|
466
|
+
...record
|
|
473
467
|
};
|
|
474
|
-
|
|
475
|
-
// These properties are persisted in autosaves.
|
|
468
|
+
data = Object.keys(data).reduce((acc, key) => {
|
|
476
469
|
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
477
|
-
acc[key] =
|
|
478
|
-
} else if (key === 'status') {
|
|
479
|
-
// Status is only persisted in autosaves when going from
|
|
480
|
-
// "auto-draft" to "draft".
|
|
481
|
-
acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
|
|
482
|
-
} else {
|
|
483
|
-
// These properties are not persisted in autosaves.
|
|
484
|
-
acc[key] = persistedRecord[key];
|
|
470
|
+
acc[key] = data[key];
|
|
485
471
|
}
|
|
486
472
|
|
|
487
473
|
return acc;
|
|
488
|
-
}, {
|
|
489
|
-
|
|
474
|
+
}, {
|
|
475
|
+
status: data.status === 'auto-draft' ? 'draft' : data.status
|
|
476
|
+
});
|
|
477
|
+
updatedRecord = await __unstableFetch({
|
|
478
|
+
path: `${path}/autosaves`,
|
|
479
|
+
method: 'POST',
|
|
480
|
+
data
|
|
481
|
+
}); // An autosave may be processed by the server as a regular save
|
|
482
|
+
// when its update is requested by the author and the post had
|
|
483
|
+
// draft or auto-draft status.
|
|
484
|
+
|
|
485
|
+
if (persistedRecord.id === updatedRecord.id) {
|
|
486
|
+
let newRecord = { ...persistedRecord,
|
|
487
|
+
...data,
|
|
488
|
+
...updatedRecord
|
|
489
|
+
};
|
|
490
|
+
newRecord = Object.keys(newRecord).reduce((acc, key) => {
|
|
491
|
+
// These properties are persisted in autosaves.
|
|
492
|
+
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
493
|
+
acc[key] = newRecord[key];
|
|
494
|
+
} else if (key === 'status') {
|
|
495
|
+
// Status is only persisted in autosaves when going from
|
|
496
|
+
// "auto-draft" to "draft".
|
|
497
|
+
acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
|
|
498
|
+
} else {
|
|
499
|
+
// These properties are not persisted in autosaves.
|
|
500
|
+
acc[key] = persistedRecord[key];
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return acc;
|
|
504
|
+
}, {});
|
|
505
|
+
dispatch.receiveEntityRecords(kind, name, newRecord, undefined, true);
|
|
506
|
+
} else {
|
|
507
|
+
dispatch.receiveAutosaves(persistedRecord.id, updatedRecord);
|
|
508
|
+
}
|
|
490
509
|
} else {
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
let edits = record;
|
|
510
|
+
let edits = record;
|
|
495
511
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
512
|
+
if (entity.__unstablePrePersist) {
|
|
513
|
+
edits = { ...edits,
|
|
514
|
+
...entity.__unstablePrePersist(persistedRecord, edits)
|
|
515
|
+
};
|
|
516
|
+
}
|
|
501
517
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
518
|
+
updatedRecord = await __unstableFetch({
|
|
519
|
+
path,
|
|
520
|
+
method: recordId ? 'PUT' : 'POST',
|
|
521
|
+
data: edits
|
|
522
|
+
});
|
|
523
|
+
dispatch.receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
|
|
524
|
+
}
|
|
525
|
+
} catch (_error) {
|
|
526
|
+
error = _error;
|
|
508
527
|
}
|
|
509
|
-
} catch (_error) {
|
|
510
|
-
error = _error;
|
|
511
|
-
}
|
|
512
528
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
529
|
+
dispatch({
|
|
530
|
+
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
531
|
+
kind,
|
|
532
|
+
name,
|
|
533
|
+
recordId,
|
|
534
|
+
error,
|
|
535
|
+
isAutosave
|
|
536
|
+
});
|
|
537
|
+
return updatedRecord;
|
|
538
|
+
} finally {
|
|
539
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
525
542
|
};
|
|
526
543
|
/**
|
|
527
544
|
* Runs multiple core-data actions at the same time using one API request.
|
|
@@ -546,9 +563,10 @@ export const saveEntityRecord = (kind, name, record, {
|
|
|
546
563
|
* values of each function given in `requests`.
|
|
547
564
|
*/
|
|
548
565
|
|
|
549
|
-
export const __experimentalBatch = requests => async
|
|
550
|
-
|
|
551
|
-
|
|
566
|
+
export const __experimentalBatch = requests => async _ref6 => {
|
|
567
|
+
let {
|
|
568
|
+
dispatch
|
|
569
|
+
} = _ref6;
|
|
552
570
|
const batch = createBatch();
|
|
553
571
|
const api = {
|
|
554
572
|
saveEntityRecord(kind, name, record, options) {
|
|
@@ -583,10 +601,12 @@ export const __experimentalBatch = requests => async ({
|
|
|
583
601
|
* @param {Object} options Saving options.
|
|
584
602
|
*/
|
|
585
603
|
|
|
586
|
-
export const saveEditedEntityRecord = (kind, name, recordId, options) => async
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
604
|
+
export const saveEditedEntityRecord = (kind, name, recordId, options) => async _ref7 => {
|
|
605
|
+
let {
|
|
606
|
+
select,
|
|
607
|
+
dispatch
|
|
608
|
+
} = _ref7;
|
|
609
|
+
|
|
590
610
|
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
|
591
611
|
return;
|
|
592
612
|
}
|
|
@@ -619,10 +639,12 @@ export const saveEditedEntityRecord = (kind, name, recordId, options) => async (
|
|
|
619
639
|
* @param {Object} options Saving options.
|
|
620
640
|
*/
|
|
621
641
|
|
|
622
|
-
export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
642
|
+
export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async _ref8 => {
|
|
643
|
+
let {
|
|
644
|
+
select,
|
|
645
|
+
dispatch
|
|
646
|
+
} = _ref8;
|
|
647
|
+
|
|
626
648
|
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
|
627
649
|
return;
|
|
628
650
|
}
|