Package Exports
- bound-decorator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bound-decorator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@bound decorator
Decorator for creating bound methods using Babel 7 (sometimes referred to as "autobinding").
Note: This decorator is not compatible with
legacymode for decorators, regardless of your Babel version.Also note that the ECMAScript decorators proposal is in the process of being redesigned. This redesign first became public in early 2019 and is still ongoing. As of January 2020, @babel/plugin-proposal-decorators is still based on the original stage 2 proposal, so this library is still fully compatible with it.
For Babel 6 and for TypeScript (at least as of 2018), you might be interested in these alternatives:
Installation
npm i -S bound-decoratorOr:
yarn add bound-decoratorUsage
Simply add @bound to the method you want to be bound:
import bound from 'bound-decorator'
@bound
handleClick() {}Example
Using React:
class Counter extends React.Component {
    state = {
        count: 0
    }
    @bound
    handleClick() {
        this.setState({ count: this.state.count + 1 })
    }
    render() {
        return <div onClick={this.handleClick}>{this.state.count}</div>
    }
}See also the demo directory.
Motivation
See MOTIVATION.md
License
ISC