Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Better api for EventTimer #155

Merged
merged 10 commits into from
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/EventTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,27 @@ export class EventTimer {

/**
* Initalise the EventTimer class on page.
* Returns a singleton instance of the EventTimer class and binds
* Returns the singleton instance of the EventTimer class and binds
* to window.guardian.commercialTimer. If it's been previously
* initalised and bound it returns the original instance
* Note: We save to window.guardian.commercialTimer because
* different bundles (DCR / DCP) can use commercial core, and we want
* all timer events saved to a single instance per-page
*
* @returns {EventTimer} Instance of EventTimer
*/
static init(): EventTimer {
return (window.guardian.commercialTimer ||= new EventTimer());
}

/**
* Just a helper method to access the singleton instance of EventTimer.
* Typical use case is EventTimer.get().trigger
*/
static get(): EventTimer {
return EventTimer.init();
}

constructor() {
this.events = [];
this.startTS = performance.now();
Expand Down