Skip to content

Commit

Permalink
getNetworkIdleObservable should not be called on import (#79)
Browse files Browse the repository at this point in the history
* getNetworkIdleObservable should not be called on import

* fix: init() should initialize network monitoring

---------

Co-authored-by: Andrew Hyndman <ahyndman@dropbox.com>
  • Loading branch information
ajhyndman and Andrew Hyndman authored Sep 13, 2024
1 parent d5963bf commit 6c8c17e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const init = (options?: TtvcOptions) => {

Logger.info('init()');

// initialize network monitoring
getNetworkIdleObservable();

calculator = getVisuallyCompleteCalculator();
whenActivated(() => {
void calculator.start();
Expand Down Expand Up @@ -101,7 +104,7 @@ export const cancel = (e?: Event) => calculator?.cancel(e);
* For the most accurate results, `decrementAjaxCount` should be called
* **exactly once** for each `incrementAjaxCount`.
*/
export const incrementAjaxCount = getNetworkIdleObservable().incrementAjaxCount;
export const incrementAjaxCount = () => getNetworkIdleObservable().incrementAjaxCount();

/**
* Call this to notify ttvc that an AJAX request has just resolved.
Expand All @@ -112,4 +115,4 @@ export const incrementAjaxCount = getNetworkIdleObservable().incrementAjaxCount;
* For the most accurate results, `decrementAjaxCount` should be called
* **exactly once** for each `incrementAjaxCount`.
*/
export const decrementAjaxCount = getNetworkIdleObservable().decrementAjaxCount;
export const decrementAjaxCount = () => getNetworkIdleObservable().decrementAjaxCount();

0 comments on commit 6c8c17e

Please sign in to comment.