@@ -28,39 +28,34 @@ export const createVanillaTemporal = <TState>(
2828 // Fastest way to clone an array on Chromium. Needed to create a new array reference
2929 const pastStates = get ( ) . pastStates . slice ( ) ;
3030 const futureStates = get ( ) . futureStates . slice ( ) ;
31- if ( pastStates . length === 0 ) {
32- return ;
33- }
34-
35- // Based on the steps, get values from the pastStates array and push them to the futureStates array
36- for ( let i = 0 ; i < steps ; i ++ ) {
37- const pastState = pastStates . pop ( ) ;
38- if ( pastState ) {
39- futureStates . push ( partialize ( userGet ( ) ) ) ;
40- userSet ( pastState ) ;
31+ if ( pastStates . length ) {
32+ // Based on the steps, get values from the pastStates array and push them to the futureStates array
33+ for ( let i = 0 ; i < steps ; i ++ ) {
34+ const pastState = pastStates . pop ( ) ;
35+ if ( pastState ) {
36+ futureStates . push ( partialize ( userGet ( ) ) ) ;
37+ userSet ( pastState ) ;
38+ }
4139 }
42- }
4340
44- set ( { pastStates, futureStates } ) ;
41+ set ( { pastStates, futureStates } ) ;
42+ }
4543 } ,
4644 redo : ( steps = 1 ) => {
4745 // Fastest way to clone an array on Chromium. Needed to create a new array reference
4846 const pastStates = get ( ) . pastStates . slice ( ) ;
4947 const futureStates = get ( ) . futureStates . slice ( ) ;
50- if ( futureStates . length === 0 ) {
51- return ;
52- }
53-
54- // Based on the steps, get values from the futureStates array and push them to the pastStates array
55- for ( let i = 0 ; i < steps ; i ++ ) {
56- const futureState = futureStates . pop ( ) ;
57- if ( futureState ) {
58- pastStates . push ( partialize ( userGet ( ) ) ) ;
59- userSet ( futureState ) ;
48+ if ( futureStates . length ) {
49+ // Based on the steps, get values from the futureStates array and push them to the pastStates array
50+ for ( let i = 0 ; i < steps ; i ++ ) {
51+ const futureState = futureStates . pop ( ) ;
52+ if ( futureState ) {
53+ pastStates . push ( partialize ( userGet ( ) ) ) ;
54+ userSet ( futureState ) ;
55+ }
6056 }
57+ set ( { pastStates, futureStates } ) ;
6158 }
62-
63- set ( { pastStates, futureStates } ) ;
6459 } ,
6560 clear : ( ) => {
6661 set ( { pastStates : [ ] , futureStates : [ ] } ) ;
@@ -78,10 +73,10 @@ export const createVanillaTemporal = <TState>(
7873 // Internal properties
7974 __onSave : onSave ,
8075 __handleSet : ( pastState ) => {
81- const trackingStatus = get ( ) . trackingStatus ,
82- onSave = get ( ) . __onSave ,
83- pastStates = get ( ) . pastStates . slice ( ) ,
84- currentState = partialize ( userGet ( ) ) ;
76+ const trackingStatus = get ( ) . trackingStatus ;
77+ const onSave = get ( ) . __onSave ;
78+ const pastStates = get ( ) . pastStates . slice ( ) ;
79+ const currentState = partialize ( userGet ( ) ) ;
8580 if (
8681 trackingStatus === 'tracking' &&
8782 ! equality ?.( currentState , pastState )
0 commit comments