Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,26 @@ export const saveEntityRecord =
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
const recordId = record[ entityIdKey ];

// Evaluate optimized edits.
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
for ( const [ key, value ] of Object.entries( record ) ) {
if ( typeof value === 'function' ) {
const evaluatedValue = value(
select.getEditedEntityRecord( kind, name, recordId )
);
dispatch.editEntityRecord(
kind,
name,
recordId,
{
[ key ]: evaluatedValue,
},
{ undoIgnore: true }
);
record[ key ] = evaluatedValue;
}
}

// When called with a theme template ID, trigger the compatibility
// logic.
if (
Expand Down Expand Up @@ -570,26 +590,6 @@ export const saveEntityRecord =
);

try {
// Evaluate optimized edits.
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
for ( const [ key, value ] of Object.entries( record ) ) {
if ( typeof value === 'function' ) {
const evaluatedValue = value(
select.getEditedEntityRecord( kind, name, recordId )
);
dispatch.editEntityRecord(
kind,
name,
recordId,
{
[ key ]: evaluatedValue,
},
{ undoIgnore: true }
);
record[ key ] = evaluatedValue;
}
}

dispatch( {
type: 'SAVE_ENTITY_RECORD_START',
kind,
Expand Down
Loading