Skip to content

slwzero/throttle-transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

throttle-transfer

Build Status

Wrap function into a throttle function.

Install

$ npm install throttle-transfer --save

Usage

throttle:

const throttleTransfer = require('throttle-transfer')
const throttle = throttleTransfer(fn, 600, true) 
// true means excute fn after 600ms and then every 600ms
// false means excute fn immediately and then every 600ms; 

function fn(a) {
  console.log(a)
}

debounce('hi') 
debounce('hi') 
// log 'hi' once after 600ms.

excute immediately, then throttle:

const throttleTransfer = require('throttle-transfer')
const throttle = throttleTransfer(fn, 600, false) 

function fn(a) {
  console.log(a)
}

throttle('hi') // log 'hi' immediately, no delay.
throttle('hi2') // log 'hi2' after 600ms.

excute with throttle:

const throttleTransfer = require('throttle-transfer')
const throttle = throttleTransfer(fn, 600, true)


function fn(a) {
  console.log(a)
}

throttle('hi') 
throttle('hi2') // log 'hi2' after 600ms.

bind this:

const throttleTransfer = require('throttle-transfer')
const throttle = throttleTransfer(function () {
  console.log(this === window)
}, 600, true)

window.onresize = throttle

// log 'true' when resizing the window

API

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published