0.0.1 • Published 7 years ago

@readable/lock v0.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

Standard - JavaScript Style Guide

Lock

Tool to create a trailing edge throttle out of any deferring function.

Places a lock on a function preventing its simultaneous execution. While another execution is due, all other requests to run will be ignored.

var throttle = Rd.lock(function (callback) {
  setTimeout(callback, 16)
})

window.addEventListener('resize', function () {
  throttle(function () {
    // Update DOM no more than every 16ms (~ 60fps)
  })
})
var throttledRAF = Rd.lock(requestAnimationFrame)

window.addEventListener('resize', function () {
  throttledRAF(function () {
    // Update DOM before repaint
  })
})