decorate-with-options
Installation
npm install decorate-with-options --save
Why?
If your decorator function expects options, you can call it in many different ways(see examples of usage below).
I'm tired of having to remember how exactly I have to call each decorator in my code.
With this module you don't have this problem anymore. Just wrap your decorator once and call it whichever way you want!
Works for decorators and Higher Order Components(HoC).
Usage
1. Define your decorator. It should accept class(or function) as it's first argument and other options(non functions, see here why) as next arguments.
{ // ...}
2. Wrap it in decorate-with-options
.
; myDecorator; { // ...}
3. Use it in your code in any of the following ways.
; /* As decorator */ // Simply apply it@myDecorator {} // Call it without options@ {} // Call it with options@ {} /* As HoC. Works with both classes and functions */ // Call it with Component // Call it with Component and options // Or the other way around // Currying is supportedComponent
Note
How does this module determine that the class or a function is passed in?
With a simple (typeof arg === 'function')
check.
So don't pass functions in place of options. Use an object with properties instead. That's the only constraint.
E.g. don't do this:
// Don't do thisconst someFunction = {}; @;;;Component;