Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active September 27, 2019 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pointofpresence/618eb13dab141889537068a711e63aad to your computer and use it in GitHub Desktop.
Save pointofpresence/618eb13dab141889537068a711e63aad to your computer and use it in GitHub Desktop.
import _ from 'lodash'
export function debounceRequest({ context, cb, debounceId = 'debounceId', interval = 1000 }) {
const id = `__debounce__${ debounceId }__`
if(_.isFunction(cb)) {
context[id] && context[id].cancel()
context[id] = _.debounce(cb, interval, false)
context[id]()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment