bindReporter.js 767 B

12345678910111213141516171819202122232425262728
  1. const bindReporter = (
  2. callback,
  3. metric,
  4. reportAllChanges,
  5. ) => {
  6. let prevValue;
  7. let delta;
  8. return (forceReport) => {
  9. if (metric.value >= 0) {
  10. if (forceReport || reportAllChanges) {
  11. delta = metric.value - (prevValue || 0);
  12. // Report the metric if there's a non-zero delta or if no previous
  13. // value exists (which can happen in the case of the document becoming
  14. // hidden when the metric value is 0).
  15. // See: https://github.com/GoogleChrome/web-vitals/issues/14
  16. if (delta || prevValue === undefined) {
  17. prevValue = metric.value;
  18. metric.delta = delta;
  19. callback(metric);
  20. }
  21. }
  22. }
  23. };
  24. };
  25. export { bindReporter };
  26. //# sourceMappingURL=bindReporter.js.map