New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

raf-funcs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raf-funcs

A very limited subset of requestAnimationFrame functions I use every day

latest
Source
npmnpm
Version
0.5.1
Version published
Weekly downloads
31
72.22%
Maintainers
1
Weekly downloads
 
Created
Source

raf-funcs

A very limited subset of requestAnimationFrame functions I use every day

Install

npm i raf-funcs

Package on npm

API

debounce(cb, [delay], [ctx])

Debounce a function, based on requestAnimationFrame

ArgumentAction
cbthe callback
delayoptional delay, default to 300 ms, min to 25 ms
ctxoptional context of this, default to global

Return a reference with

  • Two methods immediate and cancel
const debounce = require('raf-funcs/debounce')

var debounced = debounce(function() {
  console.log('250 ms after the last keyup')
}, 250)

input.addEventListener('keyup', debounced)

// uncomment to cancel the debounce
// debounced.cancel()

// uncomment to call it immediately
// debounced.immediate()

interval(cb, [delay], [ctx], [count])

Like setInterval but based on requestAnimationFrame

ArgumentAction
cbthe callback
delayoptional delay, default to 0 ms
ctxoptional context of this, default to global
countoptional maximum call, default to Infinity

Return a reference with

  • A property started
  • Two methods start and cancel
const interval = require('raf-funcs/interval')

var ref = interval(function() {
  console.log('every second')
}, 1000)

// true
ref.started

// uncomment to cancel the interval
// ref.cancel()

// uncomment to restart the interval (if finished or canceled)
// ref.start()

The callback cb receive two arguments

ArgumentAction
elapsedthe elapsed time since the start
stepthe step count
const interval = require('raf-funcs/interval')

// elapsed: 1010 step: 1
// elapsed: 2011 step: 2
// elapsed: 3014 step: 3
interval(function(elapsed, step) {
  console.log('elapsed:', elapsed, 'step:', step)
}, 1000, null, 3)

throttle(cb, [delay], [ctx])

Throttle a function, based on requestAnimationFrame

ArgumentAction
cbthe callback
delayoptional delay, default to 50 ms, min to 25 ms
ctxoptional context of this, default to global

Return a reference with

  • Two methods immediate and cancel
const throttle = require('raf-funcs/throttle')

var throttled = throttle(function() {
  console.log('after the first resize, then after each 250 ms elapsed')
}, 250)

window.addEventListener('resize', throttled)

// uncomment to cancel the throttle
// throttled.cancel()

// uncomment to call it immediately
// throttled.immediate()

timeout(cb, [delay], [ctx])

Like setTimeout but based on requestAnimationFrame

ArgumentAction
cbthe callback
delayoptional delay, default to 0 ms
ctxoptional context of this, default to global

Return a reference with

  • A property started
  • Two methods start and cancel
const timeout = require('raf-funcs/timeout')

var ref = timeout(function() {
  console.log('1 second later')
}, 1000)

// true
ref.started

// uncomment to cancel the timeout
// ref.cancel()

// uncomment to restart the timeout (if finished or canceled)
// ref.start()

The callback cb receive one argument

ArgumentAction
elapsedthe elapsed time since the start
const timeout = require('raf-funcs/timeout')

// elapsed: 1006
timeout(function(elapsed) {
  console.log('elapsed:', elapsed)
}, 1000)

Thanks

Mainly forked / inspired on

Performance tips from

License

MIT

Keywords

debounce

FAQs

Package last updated on 19 Jul 2016

Did you know?

Socket

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.

Install

Related posts