polymer-aging-with-ml / frontend /src /reportWebVitals.ts
devjas1
Initial Release: Polymer Aging With ML [Standalone Appliance]
4a0e21d
Raw
History Blame Contribute Delete
800 Bytes
type ReportHandler = (metric: any) => void;
const reportWebVitals = (onPerfEntry?: ReportHandler): void => {
if (onPerfEntry && typeof onPerfEntry === "function") {
import("web-vitals")
.then((wv: any) => {
const { getCLS, getFID, getFCP, getLCP, getTTFB } = wv as any;
if (typeof getCLS === "function") getCLS(onPerfEntry);
if (typeof getFID === "function") getFID(onPerfEntry);
if (typeof getFCP === "function") getFCP(onPerfEntry);
if (typeof getLCP === "function") getLCP(onPerfEntry);
if (typeof getTTFB === "function") getTTFB(onPerfEntry);
})
.catch(() => {
// optional: swallow import errors in environments where web-vitals isn't available
});
}
};
export default reportWebVitals;