UNPKG

@alterior/annotations

Version:
54 lines 2.01 kB
import { DecoratorSite, AnnotationDecoratorOptions, MutatorDefinition, AnnotationDecorator } from './annotations'; /** * Mutators are a way to define "mutation decorators" which in some way change the value * of the elements they are applied to, as opposed to "annotation decorators", which primarily * attach metadata. * * Create a mutator with Mutator.create(). */ export declare class Mutator { /** * Low-level method to ceate a new mutation decorator (mutator) based on the given function. * Use `Mutator.define()` instead. */ static create<Args extends any[]>(mutator: (target: DecoratorSite, ...args: Args) => void, options?: AnnotationDecoratorOptions<void>): AnnotationDecorator<Args>; /** * Define a new mutation decorator (mutator). * This should be called and returned from a * function definition. For example: * ``` function Name() { return Mutator.define({ invoke(site) { // ... } }) } ``` * * The `invoke()` function takes a DecoratorSite object which describes the particular * invocation that is being run, and importantly, access to the property descriptor * for the property being defined. If you wish to completely replace (or wrap) the * default value of the property or method you are replacing, set the `value` * property of the property descriptor with `site.propertyDescriptor.value` * * For example: * ``` export function RunTwice() { return Mutator.create( site => { let prop = site.propertyDescriptor; let original = prop.value; let replacement = function(...args) { original.apply(this, args); original.apply(this, args); } prop.value = replacement; } ) * ``` */ static define(definition: MutatorDefinition): ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator; } //# sourceMappingURL=mutator.d.ts.map