Skip to main content
Module

x/enzastdlib/decorators/decorator.ts>makeDecorator

enzastdlib is a set of TypeScript modules that follow a common design API philosophy aiming at sane defaults and ease-of-use targeting the Deno TypeScript runtime.
Latest
function makeDecorator
import { makeDecorator } from "https://deno.land/x/enzastdlib@v0.0.4/decorators/decorator.ts";

Returns a Decorator instance that provides for handling scoped metadata on functions.

Examples

Example 1

import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import { makeDecorator } from 'https://deno.land/x/enzastdlib/decorators/mod.ts';

type MyDecoratorValue = number;

const mydecorator = makeValidator<MyDecoratorValue>((func, value) => {
    // Our `Decorator` object provides simplified access to scoped metadata. So
    // we can use it to assign the initialization metadata to the function.
    mydecorator.set(func, value);
});

// We are initializing the decorator onto our desired function with some metadata.
mydecorator(my_func, 42);
function my_func() {
    console.log('Hello World!');
}

assertEquals(
    mydecorator.has(my_func),
    true,
);

assertEquals(
    mydecorator.get(my_func),
    42,
);

Type Parameters

InputValue
optional
Func extends FunctionBox = FunctionBox
optional
CacheValue = InputValue