Skip to content

Instantly share code, notes, and snippets.

@sanjeevsubedi
Last active March 7, 2023 15:18
Show Gist options
  • Save sanjeevsubedi/754d3cfca8c671df9b49d45605620818 to your computer and use it in GitHub Desktop.
Save sanjeevsubedi/754d3cfca8c671df9b49d45605620818 to your computer and use it in GitHub Desktop.
Angular method decorator to implement debounce
/**
* 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