Skip to content

Commit

Permalink
Add more descriptive comments
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Jun 2, 2021
1 parent 79ddad5 commit e20501c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/getCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean) => {
const firstSessionEntry = sessionEntries[0];
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];

// If the entry is part of the current session, add it.
// Otherwise, start a new session.
// If the entry occurred less than 1 second after the previous entry and
// less than 5 seconds after the first entry in the session, include the
// entry in the current session. Otherwise, start a new session.
if (sessionValue &&
entry.startTime - lastSessionEntry.startTime < 1000 &&
entry.startTime - firstSessionEntry.startTime < 5000) {
Expand All @@ -73,6 +74,8 @@ export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean) => {
sessionEntries = [entry];
}

// If the current session value is larger than the current CLS value,
// update CLS and the entries contributing to it.
if (sessionValue > metric.value) {
metric.value = sessionValue;
metric.entries = sessionEntries;
Expand Down

0 comments on commit e20501c

Please sign in to comment.