From 1b6c4b7f56f979d21ffc252c6f44a0c487a26eb2 Mon Sep 17 00:00:00 2001 From: Kirill Baldin Date: Mon, 3 Jul 2023 17:15:33 +0400 Subject: [PATCH] Replase window to self if we call the function in the context of web workers code with winsows will not work --- src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 487b227..a166e10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type Cancellable void> = { cancel(): void; }; -type WindowWithoutRAF = Omit; +type WindowWithoutRAF = Omit; type WrapperState = { cancelToken: number; @@ -31,14 +31,14 @@ const wrapperFactory = function() { return; } - if ('requestAnimationFrame' in window) { - state.cancelToken = window.requestAnimationFrame(() => { + if ('requestAnimationFrame' in self) { + state.cancelToken = self.requestAnimationFrame(() => { cb.apply(state.callbackThis, state.args); resetCancelToken(); }); } else { cb.apply(state.callbackThis, state.args); - state.cancelToken = (window as WindowWithoutRAF).setTimeout( + state.cancelToken = (self as WindowWithoutRAF).setTimeout( resetCancelToken, 1000 / 60 ); // 60 fps @@ -46,10 +46,10 @@ const wrapperFactory = function() { }; wrapper.cancel = () => { - if ('requestAnimationFrame' in window) { - window.cancelAnimationFrame(state.cancelToken); + if ('requestAnimationFrame' in self) { + self.cancelAnimationFrame(state.cancelToken); } - window.clearTimeout(state.cancelToken); + self.clearTimeout(state.cancelToken); resetCancelToken(); };