Skip to content

Commit

Permalink
Avoid mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 29, 2023
1 parent cf1b115 commit 0b1bfff
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
const nextStack = [ ...stack ];
if ( existingEditIndex !== -1 ) {
// If the edit is already in the stack leave the initial "from" value.
nextStack[ existingEditIndex ].to = to;
nextStack[ existingEditIndex ] = {
...nextStack[ existingEditIndex ],
to,
};
} else {
nextStack.push( {
kind,
Expand Down Expand Up @@ -555,14 +558,9 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
} );

if ( isCachedChange ) {
let newCache = state.cache;
edits.forEach(
( edit ) =>
( newCache = appendEditToStack( newCache, edit ) )
);
return {
...state,
cache: newCache,
cache: edits.reduce( appendEditToStack, state.cache ),
};
}

Expand Down

0 comments on commit 0b1bfff

Please sign in to comment.