babel-plugin-class-autobind
This plugin will autobind handlers all components listed in directive 'cb-class-autobind'
Example
In
'cb-class-autobind Component';
class Component {
constructor() {
}
handleMe(){}
onMe(){}
noBind(){}
}
Out
class Component {
constructor() {
this.handleMe = this.handleMe.bind(this);
this.onMe = this.onMe.bind(this);
}
handleMe() {}
onMe() {}
noBind() {}
}
Installation
$ npm install babel-plugin-class-autobind
Options
if no components are listed in directive - all handlers in file classes will be bound to class instance. (equal to cb-class-autobind *
)
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["class-autobind"]
}
Via CLI
$ babel --plugins class-autobind script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["class-autobind"]
});