Skip to content
Merged
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
24 changes: 19 additions & 5 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,29 @@ export const entities = ( state = {}, action ) => {
};
};

/**
* @typedef {Object} UndoStateMeta
*
* @property {number} offset Where in the undo stack we are.
* @property {Object} [flattenedUndo] Flattened form of undo stack.
*/

/** @typedef {Array<Object> & UndoStateMeta} UndoState */

/** @type {UndoState} */
const UNDO_INITIAL_STATE = Object.assign( [], { offset: 0 } );

/** @type {Object} */
let lastEditAction;

/**
* Reducer keeping track of entity edit undo history.
*
* @param {Object} state Current state.
* @param {UndoState} state Current state.
* @param {Object} action Dispatched action.
*
* @return {Object} Updated state.
* @return {UndoState} Updated state.
*/
const UNDO_INITIAL_STATE = [];
UNDO_INITIAL_STATE.offset = 0;
let lastEditAction;
export function undo( state = UNDO_INITIAL_STATE, action ) {
switch ( action.type ) {
case 'EDIT_ENTITY_RECORD':
Expand Down Expand Up @@ -439,7 +451,9 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
}
}

/** @type {UndoState} */
let nextState;

if ( isUndoOrRedo ) {
nextState = [ ...state ];
nextState.offset =
Expand Down