Skip to content

Commit

Permalink
Switch from $ to _
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Jan 10, 2025
1 parent d69651e commit 98dc25f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/attribution/onCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const onCLS = (
const layoutShiftTargetMap: WeakMap<LayoutShiftAttribution, unknown> =
new WeakMap();

layoutShiftManager.$onAfterProcessingUnexpectedShift = (
layoutShiftManager._onAfterProcessingUnexpectedShift = (
entry: LayoutShift,
) => {
if (entry.sources.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/attribution/onLCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const onLCP = (
const lcpEntryManager = initUnique(opts, LCPEntryManager);
const lcpTargetMap: WeakMap<LargestContentfulPaint, unknown> = new WeakMap();

lcpEntryManager.$onBeforeProcessingEntry = (
lcpEntryManager._onBeforeProcessingEntry = (
entry: LargestContentfulPaint,
) => {
if (entry.element) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/LCPEntryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

export class LCPEntryManager {
$onBeforeProcessingEntry?: (entry: LargestContentfulPaint) => void;
_onBeforeProcessingEntry?: (entry: LargestContentfulPaint) => void;

$processEntry(entry: LargestContentfulPaint) {
this.$onBeforeProcessingEntry?.(entry);
_processEntry(entry: LargestContentfulPaint) {
this._onBeforeProcessingEntry?.(entry);
}
}
24 changes: 12 additions & 12 deletions src/lib/LayoutShiftManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
*/

export class LayoutShiftManager {
$onAfterProcessingUnexpectedShift?: (entry: LayoutShift) => void;
_onAfterProcessingUnexpectedShift?: (entry: LayoutShift) => void;

$sessionValue = 0;
$sessionEntries: LayoutShift[] = [];
_sessionValue = 0;
_sessionEntries: LayoutShift[] = [];

$processEntry(entry: LayoutShift) {
_processEntry(entry: LayoutShift) {
// Only count layout shifts without recent user input.
if (entry.hadRecentInput) return;

const firstSessionEntry = this.$sessionEntries[0];
const lastSessionEntry = this.$sessionEntries.at(-1);
const firstSessionEntry = this._sessionEntries[0];
const lastSessionEntry = this._sessionEntries.at(-1);

// 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 (
this.$sessionValue &&
this._sessionValue &&
firstSessionEntry &&
lastSessionEntry &&
entry.startTime - lastSessionEntry.startTime < 1000 &&
entry.startTime - firstSessionEntry.startTime < 5000
) {
this.$sessionValue += entry.value;
this.$sessionEntries.push(entry);
this._sessionValue += entry.value;
this._sessionEntries.push(entry);
} else {
this.$sessionValue = entry.value;
this.$sessionEntries = [entry];
this._sessionValue = entry.value;
this._sessionEntries = [entry];
}

this.$onAfterProcessingUnexpectedShift?.(entry);
this._onAfterProcessingUnexpectedShift?.(entry);
}
}
10 changes: 5 additions & 5 deletions src/onCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ export const onCLS = (

const handleEntries = (entries: LayoutShift[]) => {
for (const entry of entries) {
layoutShiftManager.$processEntry(entry);
layoutShiftManager._processEntry(entry);
}

// If the current session value is larger than the current CLS value,
// update CLS and the entries contributing to it.
if (layoutShiftManager.$sessionValue > metric.value) {
metric.value = layoutShiftManager.$sessionValue;
metric.entries = layoutShiftManager.$sessionEntries;
if (layoutShiftManager._sessionValue > metric.value) {
metric.value = layoutShiftManager._sessionValue;
metric.entries = layoutShiftManager._sessionEntries;
report();
}
};
Expand All @@ -95,7 +95,7 @@ export const onCLS = (
// Only report after a bfcache restore if the `PerformanceObserver`
// successfully registered.
onBFCacheRestore(() => {
layoutShiftManager.$sessionValue = 0;
layoutShiftManager._sessionValue = 0;
metric = initMetric('CLS', 0);
report = bindReporter(
onReport,
Expand Down
2 changes: 1 addition & 1 deletion src/onLCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const onLCP = (
}

for (const entry of entries) {
lcpEntryManager.$processEntry(entry);
lcpEntryManager._processEntry(entry);

// Only report if the page wasn't hidden prior to LCP.
if (entry.startTime < visibilityWatcher.firstHiddenTime) {
Expand Down

0 comments on commit 98dc25f

Please sign in to comment.