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

Mute event listener logging #2251

Merged
merged 3 commits into from
Jan 18, 2018
Merged

Mute event listener logging #2251

merged 3 commits into from
Jan 18, 2018

Conversation

dy
Copy link
Contributor

@dy dy commented Jan 15, 2018

Fixes #1795

@alexcjohnson
Copy link
Collaborator

Ah, I see - so basically this is just attaching the event in a different way that allows us to tell the browser "yes, we know this isn't passive, stop bugging us"?

I like the _onwheel etc solution. LGTM! 💃

@@ -434,9 +434,14 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {

// everything but the corners gets wheel zoom
if(ns.length * ew.length !== 1) {
// still seems to be some confusion about onwheel vs onmousewheel...
if(dragger.onwheel !== undefined) dragger.onwheel = zoomWheel;
else if(dragger.onmousewheel !== undefined) dragger.onmousewheel = zoomWheel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep that onmousewheel handler in case we need it in older browsers?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only difference between what @dfcreative has here and what we had before is that now we always attach to either wheel or mousewheel, whereas before we could potentially attach to neither if the browser doesn't support either one (I had to play with this - you may already know this but what's going on is if the browser supports wheel, then element.onwheel = null before any handler is attached, not undefined). And even if there is a case where the browser really doesn't support either, there shouldn't be any problem attaching to a nonexistent event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. My bad. 👌

@etpinard etpinard added bug something broken status: reviewable labels Jan 16, 2018
@dy
Copy link
Contributor Author

dy commented Jan 17, 2018

@etpinard resolved

}
element._onwheel = handler;

element.addEventListener(wheelEventName, handler, {passive: false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this might break older browsers, see:

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support

I couldn't find a list of which older browsers does not support {passive: true|false}, but we should probably play it safe here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @etpinard - do we need a has-passive ala https://github.com/dfcreative/has-hover? Or even better, a module that would figure this out once and then export the correct 3rd arg to mark the listener active or passive:

var eventOpts = require('event-opts');
element.addEventListener(wheelEventName, handler, eventOpts.active); // false or {passive: false}
element.addEventListener(wheelEventName, handler, eventOpts.passive); // false or {passive: true}

Copy link
Contributor Author

@dy dy Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a polyfill default-passive-events for that. We could use detection logic from there in a way @alexcjohnson suggests.

Copy link
Contributor Author

@dy dy Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard @alexcjohnson a32a21a introduces eventListenerOptionsSupported method to detect proper way to attach events.
To make code cleaner it is possible to introduce an event binding function or use package, like emmy or similar.

@etpinard
Copy link
Contributor

Nicely done. Merge away (when you get the chance) 💃

@etpinard
Copy link
Contributor

Dima must be travelling today. Merging this thing so that it's part of 1.33.0.

@etpinard etpinard merged commit 41fc131 into master Jan 18, 2018
@etpinard etpinard deleted the passive-event-logging branch January 18, 2018 20:08
@dy dy mentioned this pull request Jan 25, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants