From 6c8c17ebd9eb00a20d6a3b97437d55ae7749e2ec Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Fri, 13 Sep 2024 15:41:17 -0400 Subject: [PATCH] getNetworkIdleObservable should not be called on import (#79) * getNetworkIdleObservable should not be called on import * fix: init() should initialize network monitoring --------- Co-authored-by: Andrew Hyndman --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9423f20..71fe1fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,9 @@ export const init = (options?: TtvcOptions) => { Logger.info('init()'); + // initialize network monitoring + getNetworkIdleObservable(); + calculator = getVisuallyCompleteCalculator(); whenActivated(() => { void calculator.start(); @@ -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. @@ -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();