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(useRafFn): Pass timestamp to user callback #2456

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions 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'
Expand All @@ -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,
Expand All @@ -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)
}
}

Expand Down