-
Notifications
You must be signed in to change notification settings - Fork 933
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
Add JSDoc annotations and documentation to the JS code #2892
Conversation
851bccb
to
1a43458
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grammatical fixes and attempts at completing descriptions. Great effort!
Thanks! I'll make corrections today. |
Just a quick note: The Future Options for Library Authors:
Just something to think about for future-proofing the docs! (out of interest I ran plain jsdoc against the directory and I believe all the errors are related to the TS issue) ❯ jsdoc -r . 2>&1 | grep 'ERROR' | wc -l
278 |
@03juan Thanks for all the comments! I've made made the updates you suggested, and also found a few other spots that needed fixed. Also, Yes, I believe you're right about JSDoc and TS syntax. It's something I tried to proactively call out in my "Key Points and Callouts" item 3:
And my "Future" item 2:
So, I was also thinking along the sames lines about what the future could potentially look like. My suggestion would be to embrace the TypeScript-style comment annotations, prioritize TS IDE/LSP compatibility, and perhaps going the next step of adding TypeScript as a dev dependency to generate type definitions. It's not strictly necessary or required by this change, but I think it's good benefits with few drawbacks. However, that may not be the direction the library maintainers want to go, and I defer to their preference. |
@tgroshon yes absolutely, I just wanted to point out the specific issues to the maintainers as well and of course defer to their vision. Your initial comment was very thorough and well reasoned, I should have referenced that and just emphasised your points. I'd aso like to see the direction of this leaning towards TS, even though I don't use it personally, simply because IDE tooling is supporting it by default these days. Unless one is hand-rolling their neovim configuration or something, but then those people know what they need to do anyways. 🤣 |
@@ -223,6 +223,9 @@ like this: | |||
Then a hook callback object could be defined and passed to the socket: | |||
|
|||
```javascript | |||
/** | |||
* @type {Object.<string, import("phoenix_live_view").ViewHook>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this render correctly when generating LV docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a valid JS code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.<string, ViewHook>
is the Google Closure syntax which is a valid syntax in JSDoc. In typescript it would be {[key: string]: ViewHook}
. Both syntaxes are understood by JSDoc and TypeScript. I'm not sure what any JSDoc annotation will do within Hex Docs.
1a4cda6
to
6055ec7
Compare
This is an amazingly good change. JSDoc is a huge step up from relying on DefinitelyTyped. It's extremely hard to keep DefinitelyTyped up to date in a library that's changing as often as Live View does. What is remaining to be done here? Is there anything I can help with? How soon could this be merged? |
@sevensidedmarble I think it's just waiting on review/comments and a merge. |
@sevensidedmarble If you want a cool project, you should check out
|
I'm honestly not sure about this PR from a maintenance perspective. I can see the benefits, but I'm not yet convinced they'll be enough of a help for us. Can you open a new PR that docs only the public interfaces? (So the ViewHook and public interface of LiveSocket ?). That I indeed seeing being helpful for folks, but I don't think the exhaustive docs on the private interfaces is necessarily what we want. Thank you! |
Thanks for taking the time to take a look at this @chrismccord! That's very reasonable a position, and I support you. The linked PR by the great @RodolfoSilva should accomplish that. If you ever want to investigate going further with typing interfaces, don't hesitate to reach out. All the best! |
Included are JSDoc annotations for every class, method, and function of all the JavaScript files in /assets/js/phoenix_live_view/.
Key Points and Callouts
them. I added some eslint-disable comments in other spots. Otherwise I ignored them. Some existing errors remain because they required changing code but I didn't want to mix code changes [even minor] with an already large change).
Future
Screenshots!
Highlighting existing code for explanations
Intellisense Suggestions
Example of how a file looks