Skip to content

Handle edge cases from add()ing elements twice #122

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

Merged
merged 2 commits into from
Feb 14, 2022

Conversation

anderoonies
Copy link
Contributor

Resolves #120

Summary

This fixes a unique edge case that could pop up if an element was add()ed twice. Adding an element only expands elementPoolSize by one, but after remove()ing that element, subsequent add()s would cause all duplicates to become active at once.

Changes:

  • Mark elements as _sortInvalidated when they're remove()d so that any subsequent add()s re-trigger a sort
  • When sorting elements in redraw, rather than counting the number of elements removed to shrink elementPoolSize, recalculate elementPoolSize by finding the last non-.alive element. This fixes the case where multiple elements are added back with a single add and elementPoolSize needs to be recalculated.

Checklist

  • npm test passes
  • Unit tests are included / updated
  • Documentation has been updated where relevant

@anderoonies anderoonies merged commit 5ad49e9 into codehs:main Feb 14, 2022
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.

add()ing an element twice can result in bugs with element sorting
1 participant