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

Add support in {add,remove}EventListener for stopPropagation and preventDefault options when passive: true #425

Closed
dead-claudia opened this issue Mar 17, 2017 · 2 comments

Comments

@dead-claudia
Copy link

This could still enable support for those features while retaining the perf improvements from using passive: true.

@annevk
Copy link
Member

annevk commented Mar 17, 2017

stopPropagation() isn't blocked to begin with and I don't see how you could enable preventDefault() without losing the benefits. The whole point is that you can't cancel the event.

@dead-claudia
Copy link
Author

I mean, effectively this:

var old = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function (listener, opts) {
    if (opts == null || !opts.passive || !opts.stopPropagation && !opts.preventDefault) {
        old.call(this, listener, opts)
    } else {
        const {stopPropagation, preventDefault} = opts
        old.call(this, ev => {
            if (stopPropagation) ev.stopPropagation()
            if (preventDefault) ev.preventDefault()
            return listener(ev)
        }, opts)
    }
}

Although, now that I think about it, the things affecting rendering performance (like scrolling) already have other ways of disabling them (like via CSS), so this would literally provide no benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants