Skip to content

Commit 95f9098

Browse files
committed
fix: add comments
1 parent d0d4383 commit 95f9098

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/event/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ export function Events(Base) {
9595
headingsInView[op](entry.target);
9696
}
9797

98-
let activeHeading = undefined;
98+
let activeHeading;
9999
if (headingsInView.size === 1) {
100+
// Get first and only item in set.
101+
// May be undefined if no headings are in view.
100102
activeHeading = headingsInView.values().next().value;
101103
} else if (headingsInView.size > 1) {
104+
// Find the closest heading to the top of the viewport
105+
// Reduce over the Set of headings currently in view (headingsInView) to determine the closest heading.
102106
activeHeading = Array.from(headingsInView).reduce(
103107
(closest, current) => {
104108
return !closest ||

0 commit comments

Comments
 (0)