@uveee/chrono
v0.4.0
Published
A library to manage requestAnimationFrame loops with priorities
Downloads
1
Maintainers
Readme
Description
Chrono is a JavaScript library that allows you to merge all your requestAnimationFrame
(rAF) loops into one for better performance and provides better control over their execution priority.
Installation
$ npm i @uveee/chrono
Usage
import Chrono from '@uveee/chrono'
function onFrame(time, deltaTime) {
// Called every frame
}
// Subscribe
const unsubscribe = Chrono.add(onFrame, 0);
// Unsubscribe
unsubscribe();
// OR
Chrono.remove(onFrame);
Methods
add(callback, priority)
Adds a new callback to the rAF loop.
callback: Function to be called every frame. priority: Number indicating the priority of the callback. Lower numbers have higher priority.
remove(callback)
Removes a callback from the rAF loop.
Examples
Basic Example
import Chrono from '@uveee/chrono';
Chrono.add((time, deltaTime) => {
console.log(`Time: ${time}, Delta Time: ${deltaTime}`);
}, 0);
Support
If you find this project helpful, please consider giving it a star on GitHub!