1

angular: debounce.decorator.ts

 2 years ago
source link: https://gist.github.com/stevenmoberg/b0f454f2a2685f9c788b4fe8c272cfb6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
debounce.decorator.ts · GitHub

Instantly share code, notes, and snippets.

/** * Debounce a method */ function debounce(ms) { return function(target: any, key: any, descriptor: any) { const oldFunc = descriptor.value const newFunc = _debounce(oldFunc,ms) descriptor.value = function() { return newFunc.apply(this,arguments) } } }

function _debounce(fn, ms) { _debounce.inProgress === undefined ? _debounce.inProgress = false : null if (!_debounce.inProgress) { _debounce.inProgress = true fn.apply() const timeout = setTimeout(() => { _debounce.inProgress = false clearTimeout(timeout) }, ms) } }


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK