Skip to content

Commit

Permalink
Core Data: Put undoIgnore option in an options object.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Sep 16, 2019
1 parent e8f75f7 commit 6013792
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ been edited.
_Parameters_

- _edits_ `Object`: Post attributes to edit.
- _undoIgnore_ `boolean`: Whether to ignore the edit in undo history or not.
- _options_ `Object`: Options for the edit.

<a name="enablePublishSidebar" href="#enablePublishSidebar">#</a> **enablePublishSidebar**

Expand Down
3 changes: 2 additions & 1 deletion docs/designers-developers/developers/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ _Parameters_
- _name_ `string`: Name of the edited entity record.
- _recordId_ `number`: Record ID of the edited entity record.
- _edits_ `Object`: The edits.
- _undoIgnore_ `boolean`: Whether to ignore the edit in undo history or not.
- _options_ `Object`: Options for the edit.
- _options.undoIgnore_ `boolean`: Whether to ignore the edit in undo history or not.

_Returns_

Expand Down
3 changes: 2 additions & 1 deletion packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ _Parameters_
- _name_ `string`: Name of the edited entity record.
- _recordId_ `number`: Record ID of the edited entity record.
- _edits_ `Object`: The edits.
- _undoIgnore_ `boolean`: Whether to ignore the edit in undo history or not.
- _options_ `Object`: Options for the edit.
- _options.undoIgnore_ `boolean`: Whether to ignore the edit in undo history or not.

_Returns_

Expand Down
15 changes: 8 additions & 7 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ export function receiveEmbedPreview( url, preview ) {
* Returns an action object that triggers an
* edit to an entity record.
*
* @param {string} kind Kind of the edited entity record.
* @param {string} name Name of the edited entity record.
* @param {number} recordId Record ID of the edited entity record.
* @param {Object} edits The edits.
* @param {boolean} undoIgnore Whether to ignore the edit in undo history or not.
* @param {string} kind Kind of the edited entity record.
* @param {string} name Name of the edited entity record.
* @param {number} recordId Record ID of the edited entity record.
* @param {Object} edits The edits.
* @param {Object} options Options for the edit.
* @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not.
*
* @return {Object} Action object.
*/
export function* editEntityRecord( kind, name, recordId, edits, undoIgnore ) {
export function* editEntityRecord( kind, name, recordId, edits, options = {} ) {
const { transientEdits = {}, mergedEdits = {} } = yield select(
'getEntity',
kind,
Expand Down Expand Up @@ -168,7 +169,7 @@ export function* editEntityRecord( kind, name, recordId, edits, undoIgnore ) {
type: 'EDIT_ENTITY_RECORD',
...edit,
meta: {
undo: ! undoIgnore && {
undo: ! options.undoIgnore && {
...edit,
// Send the current values for things like the first undo stack entry.
edits: Object.keys( edits ).reduce( ( acc, key ) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ export function setupEditorState( post ) {
* Returns an action object used in signalling that attributes of the post have
* been edited.
*
* @param {Object} edits Post attributes to edit.
* @param {boolean} undoIgnore Whether to ignore the edit in undo history or not.
* @param {Object} edits Post attributes to edit.
* @param {Object} options Options for the edit.
*
* @yield {Object} Action object or control.
*/
export function* editPost( edits, undoIgnore ) {
export function* editPost( edits, options ) {
const { id, type } = yield select( STORE_KEY, 'getCurrentPost' );
yield dispatch(
'core',
Expand All @@ -362,7 +362,7 @@ export function* editPost( edits, undoIgnore ) {
type,
id,
edits,
undoIgnore
options
);
}

Expand Down Expand Up @@ -394,7 +394,7 @@ export function* savePost( options = {} ) {
content: yield select( STORE_KEY, 'getEditedPostContent' ),
};
if ( ! options.isAutosave ) {
yield dispatch( STORE_KEY, 'editPost', edits, true );
yield dispatch( STORE_KEY, 'editPost', edits, { undoIgnore: true } );
}

yield __experimentalRequestPostUpdateStart( options );
Expand Down

0 comments on commit 6013792

Please sign in to comment.