Skip to content

Commit 0b1bfff

Browse files
committed
Avoid mutations
1 parent cf1b115 commit 0b1bfff

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/core-data/src/reducer.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
507507
const nextStack = [ ...stack ];
508508
if ( existingEditIndex !== -1 ) {
509509
// If the edit is already in the stack leave the initial "from" value.
510-
nextStack[ existingEditIndex ].to = to;
510+
nextStack[ existingEditIndex ] = {
511+
...nextStack[ existingEditIndex ],
512+
to,
513+
};
511514
} else {
512515
nextStack.push( {
513516
kind,
@@ -555,14 +558,9 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
555558
} );
556559

557560
if ( isCachedChange ) {
558-
let newCache = state.cache;
559-
edits.forEach(
560-
( edit ) =>
561-
( newCache = appendEditToStack( newCache, edit ) )
562-
);
563561
return {
564562
...state,
565-
cache: newCache,
563+
cache: edits.reduce( appendEditToStack, state.cache ),
566564
};
567565
}
568566

0 commit comments

Comments
 (0)