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

Events post-processor: consolidate events that "babble" #1546

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading