bindReporter.js 843 B

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