Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/farwayer/decorating
Helpers for decorating classes and properties
https://github.com/farwayer/decorating
Last synced: 4 days ago
JSON representation
Helpers for decorating classes and properties
- Host: GitHub
- URL: https://github.com/farwayer/decorating
- Owner: farwayer
- Created: 2018-05-09T10:45:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:57:47.000Z (almost 2 years ago)
- Last Synced: 2024-11-17T01:47:03.687Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 1.24 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Decorating
_Helpers for decorating classes and properties_
[![Build Status](https://img.shields.io/travis/farwayer/decorating.svg)](https://travis-ci.org/farwayer/decorating)
[![Coverage Status](https://img.shields.io/coveralls/farwayer/decorating.svg)](https://coveralls.io/github/farwayer/decorating?branch=master)ES3 target for TS is not supported.
```js
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 {}
```