Skip to content

Commit

Permalink
object.assign attributions
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed May 2, 2024
1 parent b7a54f1 commit 6fa9082
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/attribution/onCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ const attributeCLS = (metric: CLSMetric): CLSMetricWithAttribution => {
}
}

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as CLSMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down
5 changes: 2 additions & 3 deletions src/attribution/onFCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ const attributeFCP = (metric: FCPMetric): FCPMetricWithAttribution => {
}
}

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as FCPMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down
5 changes: 2 additions & 3 deletions src/attribution/onFID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const attributeFID = (metric: FIDMetric): FIDMetricWithAttribution => {
loadState: getLoadState(fidEntry.startTime),
};

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as FIDMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down
5 changes: 2 additions & 3 deletions src/attribution/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
loadState: getLoadState(firstEntry.startTime),
};

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as INPMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down
5 changes: 2 additions & 3 deletions src/attribution/onLCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ const attributeLCP = (metric: LCPMetric): LCPMetricWithAttribution => {
}
}

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as LCPMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down
5 changes: 2 additions & 3 deletions src/attribution/onTTFB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ const attributeTTFB = (metric: TTFBMetric): TTFBMetricWithAttribution => {
};
}

// Cast to attribution metric so it can be populated.
const metricWithAttribution = metric as TTFBMetricWithAttribution;
metricWithAttribution.attribution = attribution;
// Use Object.assign to set property to keep tsc happy.
const metricWithAttribution = Object.assign(metric, {attribution});
return metricWithAttribution;
};

Expand Down

0 comments on commit 6fa9082

Please sign in to comment.