Decoration Helper
This is a absolutely tiny library to help decorate functions or classes in a prettier way in the ugly messy pre-standardized decorator spec era of Javascript.
Features:
- Natural composition with
decorate(...).with(fn)
- Decorator style composition with
apply(...).to(fn)
- Functional
pipe(...)(fn)
andcompose(...)(fn)
included.
Installation
If you're here, you already know.
yarn add decoration-helper
Usage
To achieve this
@@withRouter@observer { console;} ;
you write this:
; { console;} withRouter observer;
or alternatively this, if you prefer:
; { console;} tomato;
Note: The order is not reversed when using decorate(obj).with(...decorators)
pipe()
and compose()
The proper functional approach would be to use pipe()
and compose()
as described by
Eric Elliot.
This post has
more details about it.
// Analogous to decorate(fn).with(...); ; { console;} observer withRouter tomato; // Analogous to apply(...).to(fn); ; { console;} withRouter observer tomato;
License
MIT