Last active
March 7, 2023 15:19
-
-
Save sanjeevsubedi/c0f112c662b20cc26937153bd221619a to your computer and use it in GitHub Desktop.
Angular method decorator to implement throttle
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 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