Tempus allows you to merge all your requestAnimationFrame
(rAF) loops in one for better performance and gives you better control over their execution priority.
$ npm i @darkroom.engineering/tempus
import Tempus from '@darkroom.engineering/tempus'
function onFrame(time, deltaTime) {
// called every frame
}
// subscribe
const unsubscribe = Tempus.add(onFrame, 0)
// unsubscribe
unsubscribe()
// OR
Tempus.remove(onFrame)
add(callback, priority)
remove(callback)
Tempus.add((time) => {
lenis.raf(time)
}, 0);
import { useFrame } from '@darkroom.engineering/hamo'
function Component() {
useFrame((time, deltaTime) => {
// called every frame
})
}
gsap.ticker.remove(gsap.updateRoot);
Tempus.add((time) => {
gsap.updateRoot(time / 1000);
}, 0);