Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
raf-throttle
Advanced tools
Throttle a function by requestAnimationFrame
raf-throttle let you create a throttled function, which only invokes the passed function at most once per animation frame on a browser or per 1000/60 ms on Node.
npm install raf-throttle --save
yarn add raf-throttle
Download the file from https://unpkg.com/raf-throttle/umd/rafThrottle.min.js,
and consume it from global as rafThrottle
.
Since most of browsers support requestAnimationFrame
by default, you can use raf-throttle
directly. However, if you want to support old browsers, you will need to polyfill requestAnimationFrame
by youself. One option is using raf
.
Avoid excessively updating the position while scrolling.
import throttle from 'raf-throttle'
const throttled = throttle(updatePosition)
window.addEventListener('scroll', throttled)
import throttle from 'raf-throttle'
$(window).on('scroll', throttle(updatePosition))
import React from 'react'
import throttle from 'raf-throttle'
class extends React.Component {
onScroll = throttle(updatePosition)
componentDidMount = () =>
window.addEventListener('scroll', this.onScroll)
componentWillUnmount = () =>
window.removeEventListener('scroll', this.onScroll)
render = () =>
/* Your code */
}
If you think the React code is verbose and you want to move them into a higher-order component, you shoul take a look at react-dom-utils
, which has done this for you.
Cancel the trailing throttled invocation.
const throttled = throttle(foo)
throttled()
throttled.cancel() // foo would never be invoked
import throttle from 'raf-throttle'
const throttled = throttle(callback)
callback
is the function to be throttled by requestAnimationFrame
.
throttled.cancel()
Cancel the trailing throttled invocation.
$ npm test
).FAQs
Throttle a function by requestAnimationFrame
The npm package raf-throttle receives a total of 14,409 weekly downloads. As such, raf-throttle popularity was classified as popular.
We found that raf-throttle 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.