1.2.2 • Published 4 years ago

decorating v1.2.2

Weekly downloads
912
License
WTFPL
Repository
github
Last release
4 years ago

Decorating

Helpers for decorating classes and properties

Build Status Coverage Status

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 {}