Skip to content

Commit

Permalink
Change implementation to use EDIT_ENTITY_RECORD
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Nov 5, 2021
1 parent 184d61e commit 52b8766
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
25 changes: 20 additions & 5 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,29 @@ export const __experimentalSaveSpecifiedEntityEdits = (
* @param {string} name Name of the entity.
* @param {Object} recordId ID of the record.
*/
export function __experimentalResetEditedEntityRecord( kind, name, recordId ) {
return {
type: 'RESET_ENTITY_RECORD_EDITS',
export const __experimentalResetEditedEntityRecord = (
kind,
name,
recordId
) => async ( { select, dispatch } ) => {
if ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) {
return;
}
const edits = select.getEntityRecordEdits( kind, name, recordId );
const editsToDiscard = {};
for ( const edit in edits ) {
editsToDiscard[ edit ] = undefined;
}
return await dispatch( {
type: 'EDIT_ENTITY_RECORD',
kind,
name,
recordId,
};
}
edits: editsToDiscard,
transientEdits: {},
meta: { undo: undefined },
} );
};

/**
* Action triggered to reset only specified properties for the entity.
Expand Down
9 changes: 0 additions & 9 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,6 @@ function entity( entityConfig ) {
...state,
[ action.recordId ]: nextEdits,
};

case 'RESET_ENTITY_RECORD_EDITS':
const {
// eslint-disable-next-line no-unused-vars
[ action.recordId ]: recordEdits,
...otherEdits
} = state;

return otherEdits;
}

return state;
Expand Down

0 comments on commit 52b8766

Please sign in to comment.