Skip to content

Interval

Tracking

Trackers.interval tracks time intervals, that is, the length of time between events.

This is useful when you’re interested in the period or frequency of events rather than event data itself.

Once initialised, call mark on the returned object to capture the elapsed time.

import { Trackers } from 'https://unpkg.com/ixfx/dist/bundle.js';
// Initialise
const t = Trackers.interval();
// Call `mark` to record the interval since last `mark` (or init)
t.mark();
...
t.mark();
// Get average time (in millis) between calls
t.avg;

For example, to figure how quickly the pointer is being clicked:

import { Trackers } from 'https://unpkg.com/ixfx/dist/bundle.js';
const clickInterval = Trackers.interval();
document.addEventListener(`click`, evt => {
clickInterval.mark();
console.log(`Average interval: ${clickInterval.avg}`);
});

The ‘typer’ demo (source) uses Trackers.interval.