Skip to content

Conversation

@killerwolf
Copy link
Owner

Addresses issue #9.

This commit refactors the event listener management in VisualImageTool to prevent potential memory leaks and ensure proper cleanup when the tool instance is destroyed.

Changes include:

  • Pre-binding event handlers in the constructor to maintain consistent function references.
  • Updating _setupEventListeners, _createFocusMarker, and _createCropOverlay (including crop handles) to use these pre-bound handlers for adding event listeners.
  • Modifying the _handleCropHandleMouseDown method to derive the handle type from event.currentTarget.dataset.handle.
  • Storing crop handle elements in this.cropHandles for easier iteration.
  • Comprehensively updating the destroy method to use the pre-bound handlers for removing all attached event listeners from window, document, image element, focus marker, crop overlay, and crop handles.
  • Nullifying bound handler references and clearing the cropHandles array in destroy for thorough cleanup.

Addresses issue #9.

This commit refactors the event listener management in VisualImageTool
to prevent potential memory leaks and ensure proper cleanup when the
tool instance is destroyed.

Changes include:
- Pre-binding event handlers in the constructor to maintain consistent
  function references.
- Updating `_setupEventListeners`, `_createFocusMarker`, and
  `_createCropOverlay` (including crop handles) to use these
  pre-bound handlers for adding event listeners.
- Modifying the `_handleCropHandleMouseDown` method to derive the
  handle type from `event.currentTarget.dataset.handle`.
- Storing crop handle elements in `this.cropHandles` for easier iteration.
- Comprehensively updating the `destroy` method to use the pre-bound
  handlers for removing all attached event listeners from window,
  document, image element, focus marker, crop overlay, and crop handles.
- Nullifying bound handler references and clearing the `cropHandles`
  array in `destroy` for thorough cleanup.
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.

2 participants