Skip to content
New issue

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

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

Already on GitHub? # to your account

Suggest list MouseEvent listener duplicates #532

Open
japonicus opened this issue Nov 25, 2024 · 0 comments
Open

Suggest list MouseEvent listener duplicates #532

japonicus opened this issue Nov 25, 2024 · 0 comments

Comments

@japonicus
Copy link

The mouse event handlers added to the 'Powered by MapBox' link at the foot of the suggestions list are added again to _footerNode each time the suggestions are redrawn. This leads to an accumulation of many duplicate 'mousedown' and 'mouseup' handlers.

// Add support for footer.
var parentDraw = typeahead.list.draw;
var footerNode = this._footerNode = getFooterNode();
typeahead.list.draw = function() {
parentDraw.call(this);
footerNode.addEventListener('mousedown', function() {
this.selectingListItem = true;
}.bind(this));
footerNode.addEventListener('mouseup', function() {
this.selectingListItem = false;
}.bind(this));
this.element.appendChild(footerNode);
};

The event handlers should be added to _footerNode only once, outside of typeahead.list.draw()

I noticed this because it was apparent that the _footerNode wasn't being garbage collected in a Single Page App that I was debugging.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant