Skip to content

Commit

Permalink
Rename getTTVC -> onTTVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hyndman committed May 17, 2022
1 parent b721716 commit 4223569
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ yarn add @dropbox-performance/ttvc
### Basic usage

```js
import {init, getTTVC} from '@dropbox-performance/ttvc';
import {init, onTTVC} from '@dropbox-performance/ttvc';

// Call this as early in pageload as possible to setup instrumentation.
init({
Expand All @@ -58,22 +58,22 @@ init({

// Reports the last visible change for each navigation that
// occurs during the life of this document.
const unsubscribe = getTTVC((measurement) => {
const unsubscribe = onTTVC((measurement) => {
console.log('TTVC:', measurement.duration);
});
```

### Report metrics to a collection endpoint

```js
import {init, getTTVC} from '@dropbox-performance/ttvc';
import {init, onTTVC} from '@dropbox-performance/ttvc';

init();

let measurements = [];

// capture measurements in client
getTTVC((measurement) => {
onTTVC((measurement) => {
measurements.append(measurement);
});

Expand All @@ -93,11 +93,11 @@ Capture a span using the [Performance Timeline](https://developer.mozilla.org/en
NOTE: Setting arbitrary start and end times with `performance.measure` relies on the [User Timing Level 3](https://w3c.github.io/user-timing/) specification. This is not yet adopted by all major browsers.

```js
import {init, getTTVC} from '@dropbox-performance/ttvc';
import {init, onTTVC} from '@dropbox-performance/ttvc';

init();

getTTVC(({start, end, duration, detail}: Metric) => {
onTTVC(({start, end, duration, detail}: Metric) => {
window.performance.measure('TTVC', {
start,
end,
Expand All @@ -117,11 +117,11 @@ To trigger a new navigation measurement, call `start()` or dispatch a "locationc

```js
// analytics.js
import {init, getTTVC} from '@dropbox-performance/ttvc';
import {init, onTTVC} from '@dropbox-performance/ttvc';

init();

getTTVC((measurement) => {
onTTVC((measurement) => {
console.log('TTVC:', measurement.duration);
});
```
Expand Down Expand Up @@ -229,17 +229,17 @@ Start a new TTVC measurement.

You _do not_ need to call this for the initial page load. Use this to notify `@dropbox/ttvc` that a new client-side navigation is about to take place.

#### `getTTVC()`
#### `onTTVC()`

```typescript
type getTTVC = (subscriber: (metric: Metric) -> void) -> () => void;
type onTTVC = (subscriber: (metric: Metric) -> void) -> () => void;
```

Register a callback function as a subscriber to new TTVC metric measurements. Returns an "unsubscribe" function which may be called to unregister the subscribed callback function.

The callback function may be called more than once if in-page navigation occurs.

`getTTVC` may be called more than once to register more than one subscriber.
`onTTVC` may be called more than once to register more than one subscriber.

#### `incrementAjaxCount() & decrementAjaxCount()`

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const init = (options?: TtvcOptions) => {
* NOTE: init() must be called before registering a TTVC subscriber.
*
* @example
* const unsubscribe = getTTVC(ms => console.log(ms));
* const unsubscribe = onTTVC(ms => console.log(ms));
*
* @param callback Triggered once for each navigation instance.
* @returns A function that unsubscribes the callback from this metric.
*/
export const getTTVC = (callback: MetricSubscriber) => calculator?.getTTVC(callback);
export const onTTVC = (callback: MetricSubscriber) => calculator?.onTTVC(callback);

/**
* Begin measuring a new navigation.
Expand Down
2 changes: 1 addition & 1 deletion src/visuallyCompleteCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class VisuallyCompleteCalculator {
}

/** subscribe to Visually Complete metrics */
getTTVC = (subscriber: MetricSubscriber) => {
onTTVC = (subscriber: MetricSubscriber) => {
// register subscriber callback
this.subscribers.add(subscriber);

Expand Down
2 changes: 1 addition & 1 deletion test/server/public/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ window.fetch = (...args) => {

TTVC.init({debug: true, networkTimeout: window.NETWORK_TIMEOUT ?? 3000});

TTVC.getTTVC((measurement) => {
TTVC.onTTVC((measurement) => {
console.log('TTVC:', measurement);
window.entries.push(measurement);
});

0 comments on commit 4223569

Please sign in to comment.