https://github.com/webreflection/reraf
A super light and simple way to reschedule animation frames
https://github.com/webreflection/reraf
Last synced: over 1 year ago
JSON representation
A super light and simple way to reschedule animation frames
- Host: GitHub
- URL: https://github.com/webreflection/reraf
- Owner: WebReflection
- License: isc
- Created: 2019-10-27T11:20:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-10T11:45:54.000Z (over 6 years ago)
- Last Synced: 2024-12-31T15:18:19.680Z (over 1 year ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 20
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reraf
[](https://travis-ci.com/WebReflection/reraf) [](https://coveralls.io/github/WebReflection/reraf?branch=master)
**Social Media Photo by [Hans Eiskonen](https://unsplash.com/@eiskonen) on [Unsplash](https://unsplash.com/)**
A super light and simple way to reschedule animation frames, compatible with every browser and Node.js through a `setTimeout` and `clearTimeout` fallback.
```js
import reraf from 'reraf';
// or const reraf = require('reraf');
// or
const reschedule = reraf(/* optional integer limit */);
reschedule(console.log, null, ['first']);
reschedule(console.log, null, ['second']);
// will log "second", but never "first"
```
The `reschedule(...)` returns a function to be able to `stop()` the scheduled animation frame, in case it's needed.
If a `truthy` value is passed to `stop(truthy)`, the callback will be "flushed" (invoked) if it didn't flush already.
The `stop(...)` function returns a boolean value, indicating the stop actually stopped the execution of the callback, or it didn't, 'cause it happened before.