collection-decorator
Decorator for adding to collection
Typical usecase for this library:
import { createCollectionDecorator } from 'collection-decorator';
interface ClassType {
foo: number;
}
const { collection, decorator } =
createCollectionDecorator<ClassType>();
export function fooSum() {
let sum = 0;
for (let value of collection.values()) {
sum += value.foo
}
return sum;
}
export const HasFoo = decorator;
import { HasFoo } from './HasFoo.ts';
@HasFoo
export class A {
static foo = 1;
}
import { HasFoo } from './HasFoo.ts';
@HasFoo
export class B {}
@HasFoo
export class B {
static foo = 2;
}
import { fooSum } from './HasFoo.ts';
fooSum()