Skip to content

Commit

Permalink
Events post-processor: consolidate events that "babble"
Browse files Browse the repository at this point in the history
It seems possible to end up with events that bubble for some target interfaces
but don't for other target interfaces, see discussion in:
w3c/webref#1212

The post-processor already knew how to assign a bubbling flag per target
interface because we make a distinction between interfaces that are in a
bubbling tree and interfaces that are not.

However, the post-processor did not know how to consolidate an entry that
appears duplicated in the events extract because the underlying event bubbles
in one case but not in the other. This update makes it able to consolidate
these events (which I call "babbling" events because, hey, it's Friday
evening).

We still don't have post-processing tests but that seems to work fine on Webref
data.
  • Loading branch information
tidoust committed Apr 19, 2024
1 parent 915508d commit a0ddffd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/postprocessing/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ module.exports = {
})
.filter(event => !!event);

// Before we clean and sort the result, we'll consolidate events that
// don't always bubble. We'll call them... "babbling" events. Such events
// should remain exceptions to the rule, and will likely be artificially
// created through some patching mechanism (in Webref typically) because
// the events extraction logic does not (yet?) support this scenario.
return events
.filter(event => !eventsToDrop.includes(event))
.filter(event => consolidateBabblingEvent(event, events))
.map(event => {
cleanTargetInterfaces(event, parsedInterfaces);
delete event.spec;
Expand Down Expand Up @@ -223,3 +229,31 @@ function extendEvent(event, events) {
{ spec: event.spec.series.shortname },
event.src?.href ? { href: event.src?.href } : {}));
}


/**
* Consolidate events that got duplicated in the extract because they bubble
* or don't bubble depending on the target interface.
*
* We'll say that these events "babble" because they don't seem to know whether
* they bubble or not.
*/
function consolidateBabblingEvent(event, events) {
if (event.mergedIntoAnotherEvent) {
return null;
}
const newTargets = events
.filter(e =>
e !== event && !e.isExtension && !e.mergedIntoAnotherEvent &&
e.href && e.href === event.href && e.cancelable === event.cancelable)
.map(e => {
// Flag the event as merged so that we can filter it out afterwards
e.mergedIntoAnotherEvent = true;
return e.targets;
})
.flat();
if (newTargets.length > 0) {
event.targets = (event.targets || []).concat(newTargets);
}
return event;
}

0 comments on commit a0ddffd

Please sign in to comment.