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 { interval } from 'https://unpkg.com/@ixfx/trackers/bundles';
// Initialiseconst t = interval();
// Call `mark` to record the interval since last `mark` (or init)t.mark();...t.mark();
// Get average time (in millis) between callst.avg;
For example, to figure how quickly the pointer is being clicked:
import { interval } from 'https://unpkg.com/@ixfx/trackers/bundles';const clickInterval = interval();
document.addEventListener(`click`, evt => { clickInterval.mark(); console.log(`Average interval: ${clickInterval.avg}`);});
The ‘typer’ demo (source) uses Trackers.interval
.
Importing
// Whole moduleimport * as Trackers from "@ixfx/trackers"
// Single functionimport { interval } from "@ixfx/trackers"
// One of several modulesimport { Trackers, Modulation, Flow, Data } from "@ixfx"
// And within your HTML's <HEAD> </HEAD> block:<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>
// Whole moduleimport * as Trackers from "@ixfx/trackers.js"
// Single functionimport { interval } from "@ixfx/trackers.js"
// One of several modulesimport { Trackers, Modulation, Flow, Data } from "@ixfx/bundle.js"
// Single module from the bundleimport { Trackers } from "https://unpkg.com/@ixfx/bundle"
// Single moduleimport * as Trackers from "https://unpkg.com/@ixfx/trackers/bundle"
// One of several modulesimport { Trackers, Modulation, Flow, Data } from "https://unpkg.com/@ixfx/bundle"