Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel Classes #1

Closed
talltyler opened this issue Jun 29, 2015 · 4 comments
Closed

Babel Classes #1

talltyler opened this issue Jun 29, 2015 · 4 comments

Comments

@talltyler
Copy link

ES6 classes don't map function names correctly. Every function is named 'value'.

@ctumolosus
Copy link
Owner

Not sure how you are annotating them but this works for me:

import React from 'react';

/**
 * @class TimerExample
 * @extends {React.Component}
 */
class TimerExample extends React.Component {

    /**
     * Called before our render function. The object that is returned is
     * assigned to `this.state`, so we can use it later.
     * @memberOf TimerExample.prototype
     * @method getInitialState
     * @return {Object}
     */
    getInitialState() {
        return { elapsed: 0 };
    }

    /**
     * Called by React when the component has been rendered on the page. We can
     * set the interval here.
     * @memberOf TimerExample.prototype
     * @method componentDidMount
     */
    componentDidMount() {
        this.timer = setInterval(this.tick, 50);
    }

    /**
     * Called immediately before the component is removed from the page and
     * destroyed. We can clear the interval here.
     * @memberOf TimerExample.prototype
     * @method componentWillUnmount
     */
    componentWillUnmount() {
        clearInterval(this.timer);
    }

    /**
     * Called every 50 ms to update the elapsed counter. Calling setState causes
     * the component to be re-rendered.
     * @memberOf TimerExample.prototype
     * @method tick
     */
    tick() {
        this.setState({elapsed: new Date() - this.props.start});
    }

    render() {
        var elapsed = Math.round(this.state.elapsed / 100);

        // This will give a number with one digit after the decimal dot (xx.x):
        var seconds = (elapsed / 10).toFixed(1);

        // Although we return an entire <p> element, react will smartly update
        // only the changed parts, which contain the seconds variable.
        return <p>This example was started <b>{seconds} seconds</b> ago.</p>;
    }
}

export default TimerExample;

@imyzf
Copy link

imyzf commented Aug 5, 2015

+1, solved after adding @method.

@ctumolosus
Copy link
Owner

It's probably not the most elegant solution, but until JSDoc provides support for ES6 there isn't much that can be done. Essentially this plugin is transpiling the ES6 files prior to piping them through JSDoc. The comments are maintained, but JSDoc doesn't know how to grab the method name from the transpiled code. So it needs help.

@reyalpsirc
Copy link

This doesn't work with arrow functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants