From ef90302dad25267528a390d0b49c287e2190f53e Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 17 Nov 2022 15:14:52 -0600 Subject: [PATCH] feat(useRafFn): Pass timestamp to user callback --- packages/core/useRafFn/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/useRafFn/index.ts b/packages/core/useRafFn/index.ts index 748684e347a..83c49772019 100644 --- a/packages/core/useRafFn/index.ts +++ b/packages/core/useRafFn/index.ts @@ -1,5 +1,5 @@ import { ref } from 'vue-demi' -import type { Fn, Pausable } from '@vueuse/shared' +import type { Pausable } from '@vueuse/shared' import { tryOnScopeDispose } from '@vueuse/shared' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -20,7 +20,7 @@ export interface UseRafFnOptions extends ConfigurableWindow { * @param fn * @param options */ -export function useRafFn(fn: Fn, options: UseRafFnOptions = {}): Pausable { +export function useRafFn(fn: FrameRequestCallback, options: UseRafFnOptions = {}): Pausable { const { immediate = true, window = defaultWindow, @@ -29,18 +29,18 @@ export function useRafFn(fn: Fn, options: UseRafFnOptions = {}): Pausable { const isActive = ref(false) let rafId: null | number = null - function loop() { + function loop(timestamp: DOMHighResTimeStamp) { if (!isActive.value || !window) return - fn() + fn(timestamp) rafId = window.requestAnimationFrame(loop) } function resume() { if (!isActive.value && window) { isActive.value = true - loop() + rafId = window.requestAnimationFrame(loop) } }