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

Annotate callback parameters #2417

Closed
oyvindberg opened this issue Dec 7, 2015 · 10 comments
Closed

Annotate callback parameters #2417

oyvindberg opened this issue Dec 7, 2015 · 10 comments
Labels
docs Improvements or additions to the documentation

Comments

@oyvindberg
Copy link
Contributor

So, I know the React world hasn't really embraced this yet - somehow all functions are equal for the prop types. I wanted to bring this up since you are doing a pass over/inlining the documentation anyway. Would you consider enforcing/documenting callback parameters while you're at it?

ideally we could write custom prop types for functions:

    /**
     * Callback function for when the title text is selected via a touch tap.
     */
    onTitleTouchTap: Mui.PropTypes.func1(Mui.PropTypes.Event.isRequired),

Or alternatively, there would be some value in a textual description too :

    /**
     * Callback function for when the title text is selected via a touch tap.
     * @arg Mouse or Touch event
     */
    onTitleTouchTap: React.PropTypes.func,

Or whatever else have you that already exists in some form. I would definitely be willing to help out here if you agree it's a good idea.

@oliviertassinari
Copy link
Member

I like the first example.
It would allow us to check the function parameters at run time and improve the document geneneration.
However, reactjs/react-docgen#33 would probably need to be resolved first.

For the second example, I'm not sure this is supported by react-docgen: to try.

@oliviertassinari oliviertassinari modified the milestones: Declarative API, Improve the documentation Dec 7, 2015
@oyvindberg
Copy link
Contributor Author

Yeah, i noticed that functionality was missing myself the other day while looking at it. For material-ui we need it already to support the custom prop types in prop-types.js.

I have no idea how much work it would be to hack react-docgen into supporting it. sounds easy, but... hehe. im not a terribly good js developer, for one :)

@alitaheri
Copy link
Member

@oliviertassinari We shouldn't check the provided callback to see if it's correct. Because people might want to pass a function that takes nothing for the purpose of only knowing about the event, or takes a lot of other things.

I like the second example more though. we can really extend it good with doctrine. Checkout how awesome it is :D

Oliver it's easy to just pass the description text to that lib to get a json structure so we can generate our own way of representing the callbacks. what do you say?

we can use @param tags to represent the values that will be passed to the callback

@oliviertassinari
Copy link
Member

@alitaheri Wow, doctrine looks awesome.
You definitly changed my mind 👍.

@alitaheri
Copy link
Member

@oliviertassinari Thanks 😁 I'll try to tackle with it a bit to see how we should use the output and generate proper signature documentation. We definitely need this 👍 👍

@oliviertassinari
Copy link
Member

We have chosen to implement solution n°2.
Now, we should document all of our function parameters.

@alitaheri
Copy link
Member

Now, we should document all of our function parameters.

Oooh right... there's that...

@oliviertassinari
Copy link
Member

Well, that's not a priority for me 😁.

@alitaheri
Copy link
Member

I've got it, don't worry 😁

@oliviertassinari
Copy link
Member

Please refer to #3096 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

No branches or pull requests

3 participants