Experimental decorators for common patterns.
Decorators may also be imported from
Automatically binds a class method's
this context to its current instance, even when the method is
dereferenced, which is the primary use-case for this decorator. This is an alternative to manually
bind()ing within the constructor, or using class properties with anonymous functions.
Debounce(delay: number): MethodDecorator
Delays the execution of the class method by the provided time in milliseconds. If another method call occurs within this timeframe, the execution delay will be reset.
Debouncing only works on methods with no return.
Deprecate(message?: string): Decorator
Marks a class declaration, class method, class property, or method parameter as deprecated by logging a deprecation message to the console. Works for both static and instance members.
Memoize(options?: MemoizeHasher | MemoizeOptions): MethodDecorator
Caches the return value of a class method or getter to consistently and efficiently return the same value. By default, hashes the method's arguments to determine a cache key, but can be customized with a unique hashing function.
Memoization also works on async/promise based methods by caching the promise itself. However, if the promise is rejected, the cache will be deleted so that subsequent calls can refresh itself.
The memoize decorator supports the following options:
MemoizeCache<T>) - A custom
Mapinstance to store cached values. Can also be used to pre-cache expected values.
number) - Time in milliseconds in which to keep the cache alive (TTL). Pass
0to cache indefinitely. Defaults to
MemoizeHasher) - A hashing function to determine the cache key. Is passed the method's arguments and must return a string. If not provided, arguments are hashed using
Throttle(delay: number): MethodDecorator
Throttles the execution of a class method to only fire once within every delay timeframe (in milliseconds). Will always fire on the first invocation.
Throttling only works on methods with no return.