andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances
MIT License
1.45k stars 66 forks source link

Async support #48

Closed damianobarbati closed 7 years ago

damianobarbati commented 7 years ago

Is async supported?

export default class Component extends React.Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        const { dispatch } = this.props;
        dispatch(init());
    }

    @autobind
    async compute () {
        const { dispatch } = this.props;
        let result = await dispatch(compute());
        console.log('computed:', result);
    }

    render() {
        const props = this.props;

        return (
            <div>
                <p>{props.fetching}</p>
                <p>{props.success}</p>
                <p>{props.failure}</p>
                <button type="button" onClick={this.compute} value={'Compute'} />
            </div>
        );
    }
}
damianobarbati commented 7 years ago

Yes it is. Sorry for the useless issue.