Last active
March 7, 2023 15:18
-
-
Save sanjeevsubedi/754d3cfca8c671df9b49d45605620818 to your computer and use it in GitHub Desktop.
Angular method decorator to implement debounce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Angular method decorator to implement debounce | |
* | |
*/ | |
import d from 'lodash/debounce'; | |
export function debounce(milliseconds: number = 500) { | |
return function ( | |
prototype: any, | |
name: string, | |
descriptor: PropertyDescriptor | |
) { | |
const original = descriptor.value; | |
descriptor.value = d(original, milliseconds); | |
}; | |
} | |
/** | |
* How to use it? | |
* | |
* @debounce(1000) | |
* search(event: KeyboardEvent) { | |
* ........... | |
* } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment