quark-decorators
Simple decorators (ES2016) based on Decorator design pattern.
This package is part of quark
framework but it can be used independently.
Installation
npm install quark-decorators --save
Note : In order to use decorators properly, you need a compiler like Babel 6.
Also, you need to install Babel legacy decorator plugin :
npm install babel-plugin-transform-decorators-legacy --save-dev
And add the following line to your Babel configuration :
Usage
Bind
Method only
Binds a class method to the current context.
@bind { return this } const testInstance = const test = testInstance console // = true
Mixin
Class only
Mixes object(s) with a class prototype.
Single mixin
const TestMixin = { return true } @ const testInstance = console // = true
Multiple mixins
const Test1Mixin = { return true } const Test2Mixin = { return false } @ const testInstance = console // = false (last mixin method value)
Mixin with multiple types property
const TestMixin = foo: 'bar' { return 'bar' } @ const testInstance = console // = 'bar'console // = 'bar'
API
See https://fm-ph.github.io/quark-decorators/
Build
To build the sources with babel
in ./lib
directory :
npm run build
Documentation
To generate the JSDoc
:
npm run docs
To generate the documentation and deploy on gh-pages
branch :
npm run docs:deploy
Testing
To run the tests, first clone the repository and install its dependencies :
git clone https://github.com/fm_ph/quark-decorators.gitcd quark-decoratorsnpm install
Then, run the tests :
npm test
To watch (test-driven development) :
npm run test:watch
For coverage :
npm run test:coverage
License
MIT License © Patrick Heng Fabien Motte