Skip to content

Instantly share code, notes, and snippets.

@sanjeevsubedi
Last active March 7, 2023 15:19
Show Gist options
  • Save sanjeevsubedi/c0f112c662b20cc26937153bd221619a to your computer and use it in GitHub Desktop.
Save sanjeevsubedi/c0f112c662b20cc26937153bd221619a to your computer and use it in GitHub Desktop.
Angular method decorator to implement throttle
/**
* Angular method decorator to implement throttle
*
*/
import t from 'lodash/throttle';
export function throttle(milliseconds: number = 500) {
return function (
prototype: any,
name: string,
descriptor: PropertyDescriptor
) {
const original = descriptor.value;
descriptor.value = t(original, milliseconds);
};
}
/**
* How to use it?
*
* @throttle(1000)
* scroll() {
* ...........
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment