Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
rifraf
Advanced tools
Readme
A simple requestAnimationFrame (rAF) wrapper/polyfill with added iteratee creator.
All examples below assume that you've already required rifraf: var rifraf = require('rifraf');
<Function> fn
, <Object:optional> ctx
)Queues a callback to run before the next frame. Returns the rAF (or timeout, if polyfilled) handle. Pre-binds optional context object, if provided.
// rifraf.request returns the runtime-assigned handle that can be used to cancel the callback
var handle = rifraf.request(function () {
// code to run before next frame
});
handle
)Cancels a previously request using the returned handle.
// where handle is the return value of a rifraf.request call
rifraf.cancel(handle);
<Function> fn
, <Object:optional> ctx
)alias: deferred
Used to defer expensive iterations or event handlers that need to wait until after all current DOM operations complete. Returns a new function that when called queues fn bound with ctx or its own this and its arguments.
// with context object
$('a[href]').each(rifraf.iteratee(function (i, el) {
if ($(el).data('id') === this.id) {
// expensive DOM ops here
}
}, {id: 1}));
// without context object
$('a[href]').each(rifraf.iteratee(function () {
var $el = $(this);
// expensive DOM ops here
}));
<Function> fn
, <Object:optional> ctx
, <Number:optional> _delay
)When you want to defer a function call, but your desired frame rate differs from native, delay
is for you. Pre-binds context, if provided.
// with context
rifraf.delay(function () {
console.log('My name is %s', this.name);
}, {name: 'Foo'});
// the next two are equivalent and will set the delay to ~24ms
rifraf.delay(function () {}, 24);
rifraf.delay(function () {}, null, 24);
<Function> fn
, <Object:optional> ctx
, <Number:optional> delay
)Used like iteratee
, but when you want to delay
not simply defer to next native frame. Call signature matches delay
.
var delayedDefault = rifraf.delayed(function (i, el) {
console.log('href:', this.href);
});
$('a[href]').each(delayedDefault);
var delayed24ms = rifraf.delayed(function () {}, 24);
Sets default delay time for delay
, delayed
(and polyfilled request
and iteratee
) methods to 8ms (roughly: 1000 / 120).
Sets default delay time for delay
, delayed
(and polyfilled request
and iteratee
) methods to 16ms (roughly: 1000 / 60).
Sets default delay time for delay
, delayed
(and polyfilled request
and iteratee
) methods to 33ms (roughly: 1000 / 30).
<Number> delay
)Sets default delay time for delay
, delayed
(and polyfilled request
and iteratee
) methods to {delay}
ms.
FAQs
A simple requestAnimationFrame wrapper with added iteratee creator.
We found that rifraf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).