decorating
v1.2.2
Published
Helpers for decorating classes and properties
Downloads
150
Maintainers
Readme
Decorating
Helpers for decorating classes and properties
ES3 target for TS is not supported.
import {propertyDecorator, classDecorator} from 'decorating'
const alwaysZero = propertyDecorator((target, property, desc) => {
return {get: () => 0, set: () => {}};
});
const always = propertyDecorator((target, property, desc, value) => {
return {get: () => value, set: () => {}};
});
const alwaysTwo = always(2);
class TestProps {
@alwaysZero a;
@alwaysZero() b;
@always(1) c;
@alwaysTwo d;
}
const banana = classDecorator(Class => {
Class.whaaat = 'BANANA!';
});
const whaaat = classDecorator((Class, value='DEFAULT') => {
Class.whaaat = value;
});
@banana class TestClass {}
@banana() class TestClass2 {}
@whaaat class TestClass3 {}
@whaaat() class TestClass4 {}
@whaaat('BANANA!') class TestClass5 {}