@boost/decorators
Advanced tools
Comparing version 2.1.3 to 2.1.4
@@ -0,2 +1,6 @@ | ||
/** | ||
* A method decorator that automatically binds a class method's | ||
* `this` context to its current instance. | ||
*/ | ||
export declare function Bind(): MethodDecorator; | ||
//# sourceMappingURL=Bind.d.ts.map |
@@ -0,2 +1,6 @@ | ||
/** | ||
* A method decorator that delays the execution of the class method | ||
* by the provided time in milliseconds. | ||
*/ | ||
export declare function Debounce(delay: number): MethodDecorator; | ||
//# sourceMappingURL=Debounce.d.ts.map |
@@ -0,2 +1,7 @@ | ||
/** | ||
* A decorator that marks a class declaration, class method, | ||
* class property, or method parameter as deprecated by | ||
* logging a deprecation message to the console. | ||
*/ | ||
export declare function Deprecate(message?: string): (target: Function | Object, property?: string | symbol | undefined, descriptor?: unknown) => void; | ||
//# sourceMappingURL=Deprecate.d.ts.map |
@@ -8,7 +8,20 @@ export declare type MemoizedFunction<T> = (...args: unknown[]) => T; | ||
export interface MemoizeOptions<T> { | ||
/** A custom `Map` instance to store cached values. Can also be used to pre-cache expected values. */ | ||
cache?: MemoizeCache<T> | null; | ||
/** | ||
* Time in milliseconds in which to keep the cache alive (TTL). | ||
* Pass `0` to cache indefinitely. Defaults to `0`. | ||
*/ | ||
expires?: number; | ||
/** | ||
* 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 `JSON.stringify()`. | ||
*/ | ||
hasher?: MemoizeHasher; | ||
} | ||
/** | ||
* A method decorator that caches the return value of a class method or | ||
* getter to consistently and efficiently return the same value. | ||
*/ | ||
export declare function Memoize<T>(options?: MemoizeHasher | MemoizeOptions<T>): MethodDecorator; | ||
//# sourceMappingURL=Memoize.d.ts.map |
@@ -0,2 +1,6 @@ | ||
/** | ||
* A method decorator that throttles the execution of a class method to | ||
* only fire once within every delay timeframe (in milliseconds). | ||
*/ | ||
export declare function Throttle(delay: number): MethodDecorator; | ||
//# sourceMappingURL=Throttle.d.ts.map |
@@ -14,3 +14,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
} | ||
/** | ||
* A method decorator that automatically binds a class method's | ||
* `this` context to its current instance. | ||
*/ | ||
function Bind() { | ||
@@ -43,3 +48,8 @@ return function (target, property, descriptor) { | ||
} | ||
/** | ||
* A method decorator that delays the execution of the class method | ||
* by the provided time in milliseconds. | ||
*/ | ||
function Debounce(delay) { | ||
@@ -91,3 +101,9 @@ return function (target, property, descriptor) { | ||
/** | ||
* A decorator that marks a class declaration, class method, | ||
* class property, or method parameter as deprecated by | ||
* logging a deprecation message to the console. | ||
*/ | ||
function Deprecate(message) { | ||
@@ -108,4 +124,4 @@ return function (target, property, descriptor) { | ||
else if (isParam(target, property, descriptor)) { | ||
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated.")); | ||
} | ||
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated.")); | ||
} | ||
}; | ||
@@ -165,3 +181,8 @@ } | ||
} | ||
/** | ||
* A method decorator that caches the return value of a class method or | ||
* getter to consistently and efficiently return the same value. | ||
*/ | ||
function Memoize() { | ||
@@ -210,3 +231,8 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
} | ||
/** | ||
* A method decorator that throttles the execution of a class method to | ||
* only fire once within every delay timeframe (in milliseconds). | ||
*/ | ||
function Throttle(delay) { | ||
@@ -213,0 +239,0 @@ return function (target, property, descriptor) { |
@@ -20,3 +20,8 @@ // Bundled with Packemon: https://packemon.dev | ||
} | ||
/** | ||
* A method decorator that automatically binds a class method's | ||
* `this` context to its current instance. | ||
*/ | ||
function Bind() { | ||
@@ -49,3 +54,8 @@ return function (target, property, descriptor) { | ||
} | ||
/** | ||
* A method decorator that delays the execution of the class method | ||
* by the provided time in milliseconds. | ||
*/ | ||
function Debounce(delay) { | ||
@@ -97,3 +107,9 @@ return function (target, property, descriptor) { | ||
/** | ||
* A decorator that marks a class declaration, class method, | ||
* class property, or method parameter as deprecated by | ||
* logging a deprecation message to the console. | ||
*/ | ||
function Deprecate(message) { | ||
@@ -114,4 +130,4 @@ return function (target, property, descriptor) { | ||
else if (isParam(target, property, descriptor)) { | ||
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated.")); | ||
} | ||
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated.")); | ||
} | ||
}; | ||
@@ -171,3 +187,8 @@ } | ||
} | ||
/** | ||
* A method decorator that caches the return value of a class method or | ||
* getter to consistently and efficiently return the same value. | ||
*/ | ||
function Memoize() { | ||
@@ -216,3 +237,8 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
} | ||
/** | ||
* A method decorator that throttles the execution of a class method to | ||
* only fire once within every delay timeframe (in milliseconds). | ||
*/ | ||
function Throttle(delay) { | ||
@@ -219,0 +245,0 @@ return function (target, property, descriptor) { |
@@ -8,3 +8,8 @@ 'use strict'; | ||
var isMethod = require('./helpers/isMethod.js'); | ||
/** | ||
* A method decorator that automatically binds a class method's | ||
* `this` context to its current instance. | ||
*/ | ||
function Bind() { | ||
@@ -11,0 +16,0 @@ return (target, property, descriptor) => { |
@@ -8,3 +8,8 @@ 'use strict'; | ||
var isMethod = require('./helpers/isMethod.js'); | ||
/** | ||
* A method decorator that delays the execution of the class method | ||
* by the provided time in milliseconds. | ||
*/ | ||
function Debounce(delay) { | ||
@@ -11,0 +16,0 @@ return (target, property, descriptor) => { |
@@ -16,3 +16,9 @@ 'use strict'; | ||
/** | ||
* A decorator that marks a class declaration, class method, | ||
* class property, or method parameter as deprecated by | ||
* logging a deprecation message to the console. | ||
*/ | ||
function Deprecate(message) { | ||
@@ -33,4 +39,4 @@ return (target, property, descriptor) => { | ||
else if (isParam.isParam(target, property, descriptor)) { | ||
console.debug(message !== null && message !== void 0 ? message : `Parameter ${descriptor} for \`${className + accessSymbol}()\` has been deprecated.`); | ||
} | ||
console.debug(message !== null && message !== void 0 ? message : `Parameter ${descriptor} for \`${className + accessSymbol}()\` has been deprecated.`); | ||
} | ||
}; | ||
@@ -37,0 +43,0 @@ } |
@@ -58,3 +58,8 @@ 'use strict'; | ||
} | ||
/** | ||
* A method decorator that caches the return value of a class method or | ||
* getter to consistently and efficiently return the same value. | ||
*/ | ||
function Memoize(options = {}) { | ||
@@ -61,0 +66,0 @@ // eslint-disable-next-line complexity |
@@ -8,3 +8,8 @@ 'use strict'; | ||
var isMethod = require('./helpers/isMethod.js'); | ||
/** | ||
* A method decorator that throttles the execution of a class method to | ||
* only fire once within every delay timeframe (in milliseconds). | ||
*/ | ||
function Throttle(delay) { | ||
@@ -11,0 +16,0 @@ return (target, property, descriptor) => { |
{ | ||
"name": "@boost/decorators", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "Experimental decorators for common patterns.", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "34f5c1131c16dd22e9f95bcc19e19b9a5dee1fc7" | ||
"gitHead": "a44772937c04f8f818884444faee5c2a9f44b5ac" | ||
} |
# Decorators - Boost | ||
[![Build Status](https://github.com/milesj/boost/workflows/Build/badge.svg)](https://github.com/milesj/boost/actions?query=branch%3Amaster) | ||
[![npm version](https://badge.fury.io/js/%40boost%decorators.svg)](https://www.npmjs.com/package/@boost/decorators) | ||
[![npm version](https://badge.fury.io/js/%40boost%2Fdecorators.svg)](https://www.npmjs.com/package/@boost/decorators) | ||
[![npm deps](https://david-dm.org/milesj/boost.svg?path=packages/decorators)](https://www.npmjs.com/package/@boost/decorators) | ||
@@ -41,2 +41,3 @@ | ||
[https://boostlib.dev/docs/decorators](https://boostlib.dev/docs/decorators) | ||
- [https://boostlib.dev/docs/decorators](https://boostlib.dev/docs/decorators) | ||
- [https://boostlib.dev/api/decorators](https://boostlib.dev/api/decorators) |
import { isMethod } from './helpers/isMethod'; | ||
/** | ||
* A method decorator that automatically binds a class method's | ||
* `this` context to its current instance. | ||
*/ | ||
export function Bind(): MethodDecorator { | ||
@@ -4,0 +8,0 @@ return (target, property, descriptor) => { |
import { isMethod } from './helpers/isMethod'; | ||
/** | ||
* A method decorator that delays the execution of the class method | ||
* by the provided time in milliseconds. | ||
*/ | ||
export function Debounce(delay: number): MethodDecorator { | ||
@@ -4,0 +8,0 @@ return (target, property, descriptor) => { |
@@ -8,2 +8,7 @@ /* eslint-disable no-console */ | ||
/** | ||
* A decorator that marks a class declaration, class method, | ||
* class property, or method parameter as deprecated by | ||
* logging a deprecation message to the console. | ||
*/ | ||
export function Deprecate(message?: string) { | ||
@@ -10,0 +15,0 @@ return (target: Function | Object, property?: string | symbol, descriptor?: unknown): void => { |
@@ -16,4 +16,13 @@ import { isMethod } from './helpers/isMethod'; | ||
export interface MemoizeOptions<T> { | ||
/** A custom `Map` instance to store cached values. Can also be used to pre-cache expected values. */ | ||
cache?: MemoizeCache<T> | null; | ||
/** | ||
* Time in milliseconds in which to keep the cache alive (TTL). | ||
* Pass `0` to cache indefinitely. Defaults to `0`. | ||
*/ | ||
expires?: number; | ||
/** | ||
* 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 `JSON.stringify()`. | ||
*/ | ||
hasher?: MemoizeHasher; | ||
@@ -68,2 +77,6 @@ } | ||
/** | ||
* A method decorator that caches the return value of a class method or | ||
* getter to consistently and efficiently return the same value. | ||
*/ | ||
export function Memoize<T>(options: MemoizeHasher | MemoizeOptions<T> = {}): MethodDecorator { | ||
@@ -70,0 +83,0 @@ // eslint-disable-next-line complexity |
import { isMethod } from './helpers/isMethod'; | ||
/** | ||
* A method decorator that throttles the execution of a class method to | ||
* only fire once within every delay timeframe (in milliseconds). | ||
*/ | ||
export function Throttle(delay: number): MethodDecorator { | ||
@@ -4,0 +8,0 @@ return (target, property, descriptor) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72337
1040
43