[whatwg/dom] Add more explanation for Event concepts (#863)

In https://docs.google.com/document/d/1NFARs04-4U_2y6Ssw9Lqu1GMXBUM981-NO9PLJWifTI/edit# I wrote the following explanations for event features, which we might want to consider adding into the spec itself since they are reportedly clearer than what exists today. Kudos to @benjamingr for suggesting this.

### Passive

_Responding to the misconception that passive means "doesn't block browser paint":_

This is not what passive means. Passive means that preventDefault() has no effect.

This allows the browser to perform some optimizations behind the scenes for certain events, because otherwise it has to synchronously wait for event dispatch during scrolling/etc. to see if JS code calls preventDefault(). With passive, it doesn't have to wait for event dispatch; it can just fire-and-forget the events.

### isTrusted

_Responding to the misconception that firing trusted events cause special trusted actions, like making `:hover` match:_

There isn't such a thing as a trusted action.

I think you have the architecture a bit wrong. When the user hovers their mouse over something, the browser makes :hover match, and also dispatches a mousemove event. Because the browser dispatched it, the event is marked as trusted.

The architecture is not: the user moves their mouse, the browser dispatches a trusted mousemove event, and that trusted mousemove event causes :hover to match.

isTrusted is basically a legacy feature that means "did the runtime dispatch this event". It doesn't cause more special actions to happen.

### preventDefault() / cancelation

_Responding to a framing that stopImmediatePropagation() / stopPropagation() are a form of cancelation:_

You may be conflating two things here.

Event cancelation is done with event.preventDefault(). This causes the caller of dispatchEvent() to recieve a false return value instead of true, which they may act on if they wish to cancel some in-progress process which the event was triggered from. (E.g., form submission.)

Stopping propagation with stopPropagation() and stopImmediatePropagation() is different. It modifies the propagation process, and would be a sub-bullet of "Propagation of events" IMO.

----

I'd be happy to turn these into a PR for further discussion, but could use a bit of advice as to where would be a good place to put them. Maybe https://dom.spec.whatwg.org/#introduction-to-dom-events, with cross-references from the domintro blocks ? Not sure.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/863

Received on Thursday, 7 May 2020 15:49:07 UTC