Skip to content

Commit

Permalink
feat(useRafFn): Pass timestamp to user callback
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Nov 18, 2022
1 parent 944134c commit ef90302
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit ef90302

Please sign in to comment.