Comments (12)
I don't think this is anyone's intention. I guess you're saying that if the third argument is missing, it should be treated like the default dictionary values { capture: false, mayCancel: false }
, while the current behavior is { capture: false, mayCancel: true }
?
Ways around this:
- Prose says that if the third argument is boolean, the listener's
may cancel
flag will be true. - Invert name and meaning of
mayCancel
so that false is also the current default. - A new function name.
There's also #21 casting some doubt on whether overloading the third argument will be web compatible.
from eventlisteneroptions.
Hmm, I hadn't considered 1. It is pretty crazy though. Overall I would prefer 2.
from eventlisteneroptions.
2 - leads to a double negative which can be confusing to understand. But maybe it is just me...
ie; you could call it willNotCancel
And then the default is false.
from eventlisteneroptions.
No, negative argument names are a confusing anti-pattern.
We either need to come up with a positive name of the opposite meaning, or leave it as it is, with prose making it clear that the default dictionary value (true) is used by default when the dict isn't passed.
from eventlisteneroptions.
The fundamental issue here is that we have two notions of "default". One is what we want the behavior to be for developers opting-in to the new API form but not specifying mayCancel explicitly, and one is what we need the behavior to be for code unaware of the new API form. I.e. why do we think the "default" behavior for the existing API should be the same as the "default" behavior for a new API form?
I don't think we want to invert the meaning because when the developer has opted into the new API we still want mayCancel=false
to be the default behavior (#17).
If we consider the boolean
form of addEventListener to be legacy, is it really that weird to say that it sets up an EventListenerOptions with mayCancel=true
for legacy compatibility reasons? I'll try to specify this precisely as part of #19. Any objections?
from eventlisteneroptions.
It is weird to say that addEventListener(s, f) is different than addEventListener(s, f, {}). Very, very weird.
from eventlisteneroptions.
Idea of sorts...
Change: mayCancel
-> passive
.
aEL(s, f) // passive = false
aEL(s, f, {}) // passive = false
aEL(s, f, {capture:false}) // passive = true
Once you start using the dictionary the default flips.
from eventlisteneroptions.
aEL(s, f, {}) // passive = false
aEL(s, f, {capture:false}) // passive = true
this is bizarre.
from eventlisteneroptions.
I'm not sure what the motivation here is anyway for making mayCancel false the default. It is to save characters so you can type {}
instead of { mayCancel: false }
? Why do we want to encourage that kind of obtuse coding?
from eventlisteneroptions.
@domenic No, I imagine it's so that you automatically opt into the "better" model if you're using the newer API variant. (Legacy code continues to use the legacy behavior.) Most code isn't trying to cancel anything, and as we add optimizations for non-cancelling events of various types, it's better if most stuff automatically works better.
This does mean that, right now, without very many options in the dictionary, there may be code that just does aEL(..., ..., {})
just to opt into the new API, which is indeed weird and not worth encouraging, but I also don't think it's something to fear or worth objecting to.
It is weird that aEL(a, b)
and aEL(a,b,{})` end up being different, but that's legacy upgrades for you.
(I might call the new option cancelable
rather than mayCancel
to describe the behavior of the event rather than the programmer.)
this is bizarre.
Agree that making the behavior change based on whether some keys are in the dictionary or not is bizarre and unwanted. You also need to hack around WebIDL by specifying the type as any
and handling the dictionary in prose; using IDL properly won't let you do this bizarre behavior.
from eventlisteneroptions.
using IDL properly won't let you do this bizarre behavior
Euhm yes it would. You just don't define defaults. Mutation observers does something like this. Where the state of some fields depends on others to make the API more convenient to use.
from eventlisteneroptions.
I've written the spec as discussed. I think it works, but I don't love it. Let's discuss further in #17.
from eventlisteneroptions.
Related Issues (20)
- Suggestion: add more event types (xxxpassive or xxx-ed) instead of EventListenerOptions HOT 4
- Write explainer doc HOT 1
- Should the passive option be part of the event listener key HOT 33
- Should passive listeners be able to stopPropagation? HOT 3
- Add simpler feature detection mechanism? HOT 21
- passive is ambiguous HOT 14
- Should preventDefault not be exposed on passive event handlers? HOT 9
- Request for an Update Demo File to be added to this Repository HOT 3
- Add library to make touch listeners passive by default
- Add library which generates "touchstarted" events HOT 1
- Could/should the polyfill simply rewrite/extend addEventListener? HOT 3
- Polyfill doesn't work in firefox 47 HOT 1
- CFC to migrate to the Web Platform WG HOT 9
- Polyfill does not work in Safari 9.1.1 HOT 4
- Modernizr.passiveeventlisteners does not exist? HOT 6
- Make it easier to target non-passive event listeners to specific classes HOT 10
- Warning keeps showing when using preventDefault? HOT 3
- Swiping horizontally in iOS 10 HOT 2
- Publish polyfill to NPM
- Should this repo be set to "archived"? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventlisteneroptions.