Skip to content

Commit

Permalink
refactor(control): refactor travels control
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Mar 23, 2024
1 parent 59c964d commit bb8de95
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ export const useTravel = <S, F extends boolean, A extends boolean>(
tempPatchesDraft.inversePatches.length = 0;
});
};
const shouldArchive = useMemo(() => !autoArchive && tempPatches.patches.length, [tempPatches]);
const shouldArchive = useMemo(
() => !autoArchive && tempPatches.patches.length,
[tempPatches]
);
const _allPatches = useMemo(() => {
let mergedPatches = allPatches;
if (shouldArchive) {
Expand Down Expand Up @@ -303,15 +306,11 @@ export const useTravel = <S, F extends boolean, A extends boolean>(
setTempPatches(() => ({ patches: [], inversePatches: [] }));
},
go,
canBack: () => {
return position > 0;
},
canForward: () => {
if (shouldArchive) {
return position < _allPatches.patches.length - 1;
}
return position < allPatches.patches.length;
},
canBack: () => position > 0,
canForward: () =>
shouldArchive
? position < _allPatches.patches.length - 1
: position < allPatches.patches.length,
archive,
};
}, [
Expand Down

0 comments on commit bb8de95

Please sign in to comment.