Skip to content

Commit

Permalink
Revert separate MetricRating type, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
robatron committed Feb 26, 2023
1 parent 99354ee commit 60b0609
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,20 @@ Metric-specific subclasses:
- [`LCPMetricWithAttribution`](/src/types/lcp.ts#:~:text=interface%20LCPMetricWithAttribution)
- [`TTFBMetricWithAttribution`](/src/types/ttfb.ts#:~:text=interface%20TTFBMetricWithAttribution)

#### `MetricThresholds`

```ts
/**
* The ranges defining a metric's "good", "needs improvement", and "poor"
* thresholds:
*
* - Metric values ≦ [0] are "good"
* - Metric values > [0] and ≦ [1] are "needs improvement"
* - Metric values > [1] are "poor".
*/
type MetricThresholds = [number, number];
```

#### `ReportCallback`

```ts
Expand Down
9 changes: 2 additions & 7 deletions src/lib/bindReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
* limitations under the License.
*/

import {
Metric,
MetricRating,
MetricThresholds,
ReportCallback,
} from '../types.js';
import {Metric, MetricThresholds, ReportCallback} from '../types.js';

const getRating = (
value: number,
thresholds: MetricThresholds
): MetricRating => {
): Metric['rating'] => {
if (value > thresholds[1]) {
return 'poor';
}
Expand Down
8 changes: 1 addition & 7 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ import {
NavigationTimingPolyfillEntry,
} from './polyfills.js';

/**
* A rating indicating if a metric's value is within its "good", "needs
* improvement", or "poor" thresholds.
*/
export type MetricRating = 'good' | 'needs-improvement' | 'poor';

/**
* The ranges defining a metric's "good", "needs improvement", and "poor"
* thresholds:
Expand All @@ -50,7 +44,7 @@ export interface Metric {
* The rating as to whether the metric value is within the "good",
* "needs improvement", or "poor" thresholds of the metric.
*/
rating: MetricRating;
rating: 'good' | 'needs-improvement' | 'poor';

/**
* The delta between the current value and the last-reported value.
Expand Down

0 comments on commit 60b0609

Please sign in to comment.