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

Fix: better state handling #3

Merged
merged 1 commit into from
Jan 1, 2024
Merged

Fix: better state handling #3

merged 1 commit into from
Jan 1, 2024

Conversation

arthurlch
Copy link
Owner

Changes to State Management:

  1. Consolidation of State using Jotai: We consolidated multiple state atoms into a single dijkstraStateAtom. This atom now holds all relevant state properties including grid, mouseIsPressed, isVisualizationStarted, startNode, finishNode, currentNode, executionTime, isAnimationFinished, and visitedNodes. This change simplifies state management and ensures consistency across the application.

  2. Updating currentNode: We modified the animateDijkstra function to correctly update currentNode in the state. This change ensures that the current node being processed in the Dijkstra algorithm is accurately tracked and can be displayed in the UI.

  3. Debugging and Logging: Added console logs for debugging purposes. These logs are essential to trace the flow of state changes and identify any issues in real-time.

Changes to Grid State:

  1. Handling Wall Drawing: Updated the handleMouseDown and handleMouseEnter functions to modify the grid state correctly when walls are drawn. These changes ensure that when a user interacts with the grid (drawing walls), the grid state is accurately updated.

  2. Isolation Check Function: Implemented a new function checkStartFinishIsolation to determine if the start or finish nodes are isolated by walls. This function enhances the algorithm by preventing it from running if either the start or finish node is completely surrounded by walls, which would make finding a path impossible.

  3. Refactoring for Efficiency: Refactored the grid initialization and node creation logic to make it more efficient and readable. This includes streamlined creation of nodes and initialization of the grid, which is especially important for larger grids.

Other Key Points for the PR:

  • Code Comments: Added comprehensive comments explaining the logic and purpose of the new changes, making the code easier to understand and maintain.
  • Testing: Extensive testing was conducted to ensure that all new changes work as expected and do not introduce any new bugs.
  • Backward Compatibility: Ensured that the changes are backward compatible with the existing features of the application.

PR Conclusion:

These changes aim to enhance the functionality, efficiency, and maintainability of the Dijkstra Visualizer. They address specific issues related to state management and grid interaction, resulting in a more robust application.

@arthurlch arthurlch self-assigned this Jan 1, 2024
Copy link

vercel bot commented Jan 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
algorithm-visualizer ✅ Ready (Inspect) Visit Preview Jan 1, 2024 7:50pm
reactalgovizu ✅ Ready (Inspect) Visit Preview Jan 1, 2024 7:50pm

@arthurlch arthurlch merged commit 3faadfc into main Jan 1, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant