Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be re-written to avoid loops altogether and simply use an array method to splice the array at the specific index? #105

Closed
charkour opened this issue May 30, 2023 · 2 comments · Fixed by #117
Assignees
Labels
enhancement New feature or request

Comments

@charkour
Copy link
Owner

     undo: (steps = 1) => {
        // Fastest way to clone an array on Chromium. Needed to create a new array reference
        const pastStates = get().pastStates.slice();
        const futureStates = get().futureStates.slice();
        if (pastStates.length) {
          // Based on the steps, get values from the pastStates array and push them to the futureStates array
          for (let i = 0; i < steps; i++) {
            const pastState = pastStates.pop();
            if (pastState) {
              futureStates.push(options?.partialize?.(userGet()) || userGet());
              userSet(pastState);
            }
          }
          set({ pastStates, futureStates });
        }
@charkour
Copy link
Owner Author

@charkour
Copy link
Owner Author

#117

@charkour charkour self-assigned this Jun 17, 2023
@charkour charkour added the enhancement New feature or request label Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant