question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dedupe event listeners

See original GitHub issue

Currently, each instead of Perimeter will register a mousemove and resize listener on window. While I don’t recommend having tons of these on a single page, it may be better for performance to register a single listener and iterate over each registered instance. So we need to:

  • Determine if its more performant to use a single listener (maybe browsers can parallelize multiple listeners better?)
  • Find a universal way for each instance to register with a global listener. The easiest solution may be to track a property on the global window but other suggestions welcome

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
jnsdlscommented, Mar 17, 2017

I agree that it’s quite a bit of moving parts if you want to make it conditional and let people pass their own register & remove listeners functions. (I like the customizability aspect but I’m not sure if it’s necessary, we should just come up with the 90 percentile best solution and go with that.)

In my proposed solution we could handle the “global vs non-global” problem very simply by the way:

  1. check if there is a MouseMoveProvider on the context
  2. if yes -> subscribe || if no -> use own window.eventListener

and then if we wanted to go super deep we could still do the eventManager as a potential prop to (think history in React-Router)

EDIT: Also first we should experiment and prove that it’s actually beneficial to have 1 global listener rather than a bunch of listeners. (I’m confident it is, but need to test what impact it makes anyways.)

1reaction
jnsdlscommented, Mar 17, 2017

Feels like a good place to use a MouseMoveProvider component wrapping the application (like the Provider from react-redux) and providing a subscription method to move events on the context -> the Perimeter component on componentWillMount subscribes to the MouseMoveProvider via the exposed context method and unsubscribes on componentWillUnmount

I feel like that should work?

Sorry for the terrible formatting, I’m on my phone. Happy to submit a PR once I get to work that implements this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Removing duplicate event listeners - javascript
I made a function that will add an event listener to a button but if the function runs again I want the event...
Read more >
How to prevent duplicate events - kiko.io
I'm working on a new web app that contains a sliding out panel with some additional information on the selected element.
Read more >
Javascript addEventListener will not duplicate named functions
Let's take the classic use of the anonymous function as an event listener. If we bind the same content multiple times to the...
Read more >
Drop most custom event listeners · Issue #5992
Reasons: deduplication logic is making things difficult; a simple selector observer is usually much easier to reason about. Related: MAIN AJAX ...
Read more >
Deduplicate events to reduce noise
Deduplication is the process of identifying repeated events and combining them into alerts. This reduces operational noise by limiting the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found