-
Notifications
You must be signed in to change notification settings - Fork 437
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
Started adding JSDoc #984
Started adding JSDoc #984
Conversation
/** | ||
* Connects a new stream source. | ||
* | ||
* @param {any} source - The new stream source to connect. |
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.
This is either EventSource | WebSocket
/** | ||
* Disconnects an existing stream source. | ||
* | ||
* @param {any} source - The stream source to disconnect. |
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.
This is either EventSource | WebSocket
Thank you for opening this. I think this is an improvement over what's currently available. I'm in favor of documentation of any kind, especially documentation that brings typed specificity. I worry that the core team's disinterest in TypeScript might extend to a disinterest in typed code comments. Even the most correctly typed JSDoc comments risk becoming useless without the support from the tooling that enforces them and the human commitment to adhere to the results of the tooling. Could this pull request also introduce tooling for CI and local development? Does the core team have interest in incorporating that tooling into the project? |
I'm highly interested in making contributions here and adding JSDoc over the whole codebase if this move is accepted.
you mean things like using |
I would also like to help out with reading types for this project. However, I would like one of the main contributors, like @.dhh, to say if they're willing to add this PR so our time doesn't get wasted reading something that was removed. |
* Initiates a visit to a specified location, with optional parameters. | ||
* | ||
* @param {string} location - The location to visit. | ||
* @param {Object} options - Optional parameters for the visit. |
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.
Would it make sense to define the options properties? This can be done via @typedef
.
/** | ||
* Sets the form mode. | ||
* | ||
* @param {string} mode - The form mode to set, either "on" or "off". |
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.
This could be typed as @param {('on'|'off')} mode
.
* | ||
* @private | ||
* @param {HTMLFormElement} form - The form element being submitted. | ||
* @param {HTMLElement} submitter - The element that triggered the form submission. |
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.
submitter
is optional, it should therefore be typed as @param {HTMLElement} [submitter]
.
This is a good idea. I did check out your branch and ran tsc to generate type definitions from this, which produces quite usable results for the files you touched: npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types |
Hey guys! So I'm waiting for answer from maintainers, if they're interested in it, I'll add infrastructure like eslint and continue writing documentation |
imho, "this is the way" (cit) the benefits of JSDoc TS are many:
last, but not least, I love the fact somebody proposed something instead of insulting people involved in this project (not everyone, but what I've read these days show how TS community can be way more toxic and hostile than anything happened in here). I hope maintainers will give this PR a chance. |
@shashkovdanil thanks for the civil and constructive approach to the PR, I really appreciate it. What we found that works for us to document Turbo is having a documentation project that you can access online. Most of the public Turbo APIs are HTML annotations (data- attributes, mostly), custom elements and events. Having a documentation website allows us to document all of those together in a consistent way. There are a few cases where you might want to call a Turbo public API directly from your code, like |
@@ -40,6 +44,9 @@ export class Session { | |||
started = false | |||
formMode = "on" | |||
|
|||
/** | |||
* Starts all observers and services if not already started. |
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.
what about adding a return here?
* @returns {void}
* Initiates a visit to a specified location, with optional parameters. | ||
* | ||
* @param {string} location - The location to visit. | ||
* @param {Object} options - Optional parameters for the visit. |
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.
since options is optional, you can use square brackets around the description
* @param {Object} [options] - Optional parameters for the visit.
@afcapel Hi, JSDoc is not only good for users who will use the public API, but it is also good for contributors. If the documentation covers all this and JSDoc is not useful, I think you can close the PR |
Hi, you might consider using |
Here's an attempt to migrate the whole codebase to JSDoc using the above mentioned The generated code is not 100% perfect in all cases, but I would be more than happy to polish this by hand if we decide to continue moving forward with this. I think having the comments/documentation is valuable for contributors to see and understand how the internals work. This is also why it's not really a solution to just push up the types to DefinitelyTyped. It's not too valuable for users using Turbo and consuming the exported types the packages ships with, it's about the context and documentation we lost about the internals. |
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.
This is a great step forward. If the devs (looking at you DHH) really want to ditch TypeScript, I think JSDoc is a great in-between
@afcapel hey, should I continue this? |
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
@shashkovdanil I'm afraid we're not interested in bringing back the type system, even if it's in the form of comments. But thanks again for the constructive approach to the discussion. |
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
It appears that the team's [official stance][] is that documentation for the package's Custom Events should reside on a consumer-facing website. The documentation for Custom Events already exists, but doesn't provide particulars for the shapes of the most of the `event.details` objects. This commit brings more structure to the page, namely: * groups events by their source * promotes event names to deeply-linkable headings * adds HTML tables to describe each event's `event.detail` properties, along with type information [official stance]: hotwired/turbo#984 (comment)
Even though I love TypeScript, I respect the decision made by the owners. I can admit that sometimes TypeScript causes a headache and you have to use
as/any/unknown
. It's also hard to read and understand what is happening in code like this.However, it must be acknowledged that the code's readability has decreased. It will be harder for users to understand how to use turbo, and for other contributors to understand what functions and methods are doing. And instead of arguing, I prefer to find compromises. Therefore, I decided to combine the best of both worlds and started adding JSDoc. You can see what this looks like in this PR. I don't want to waste my time in vain, so I'm putting this up for public judgment. If the maintainers approve this PR, I will cover the remaining code with JSDoc.