Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
subscribe-ui-event
Advanced tools
A single, throttle built-in solution to subscribe to browser UI Events.
subscribe-ui-event
provides an cross-browser and performant way to subscribe to browser UI Events.
Instead of calling window.addEvenListener('scroll', eventHandler);
, you can call subscribe('scroll', eventHandler)
and you can get lots of benifits:
requestAnimationFrame
throttle for the need of high performance.scrollTop
) to avoid multiple reflows.ynpm install subscribe-ui-event
Subscription subscribe(String eventType, Function callback, Object? options)
Provide throttled version of window or document events, such like scroll
, resize
and visibilitychange
to subscribe. It also provides some higher, compound events, such like viewportchange
, which combines scroll
, resize
and visibilitychange
events.
Note on IE8 or the below, the throttle will be turned off because the event object is global and will be deleted for setTimeout or rAF.
Example:
var subscribe = require('subscribe-ui-event').subscribe;
function eventHandler (e, payload) {
// e is the native event object and
// payload is the additional information
...
}
// 50ms throttle by default
var subscription = subscribe('scroll', eventHandler);
// remove later
subscription.unsubscribe();
options.throttleRate
allows of changing the throttle rate, and the default value is 50 (ms). Set 0 for no throttle. On IE8, there will be no throttle, because throttling will use setTimeout or rAF to achieve, and the event object passed into event handler will be overwritten.
options.context
allows of setting the caller of callback function.
options.useRAF = true
allows of using requestAnimationFrame
instead of setTimeout
. If true
, the default value of throttle rate will be 15 (ms).
eventType
could be one of the following:
Void unsubscribe(String eventType, Function callback)
Unsubscribe an event. Note that all subscriptions with the same eventHandler and the same event type will be unsubscribed together even if they have different options.
This software is free to use under the BSD license. See the LICENSE file for license text and copyright information.
FAQs
A single, throttle built-in solution to subscribe to browser UI Events.
The npm package subscribe-ui-event receives a total of 77,429 weekly downloads. As such, subscribe-ui-event popularity was classified as popular.
We found that subscribe-ui-event demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.