meta-decorator
v0.0.12
Published
function decorators
Readme
f-decorator
It implements a function decorator with global object for reflection, including IoC container and env file support.
new globals
- global.own: reflection object
- global.ioc: IoC container object (optional)
- global.env: typed env file, independent of env nodejs
own intropection
- global.own.decorators: all data decorators
- global.own.functions: all functions
- global.own.modules: all modules
object reflection
function Example() { }
Example.path // file path of function
Example.async // true if it returns Promise
Example.module // module host of Example function
Example.module.use // check if it is 'client' ou 'server'
Example.decorators // list all related function decoratorsfunction decorator
Creating a function decorator.
class log extends Decorator {
constructor(args: LogDecoratorArgs) { super(args) }
public annotation = () => 'done' // decorator.data
}
Using a function decorator.
@log({ hi: 'it works'})
function Example() { }
Example.decorators[0].name == 'log'
Example.decorators[0].data == 'done'It is transpiled as below.
const Example = new log({ hi: 'it works'})
.decorate(function Example() { })
.targetcolor syntax issue
To prevent error syntax warning, just use @ts-ignore in typescript projects.
// @ts-ignore
@log({ hi: 'it works'})
function Example() { }