-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Our docs' function signatures can get unreadable in a hurry. #21
Comments
Basically, it's moving crap from tables to code blocks with associated prose so it's easier to follow. My proposal could be summarized as this:
|
Agreed. I've edited the request docs once or twice and it's not fun in its current form. :) |
Hey there. Long time listener, first time caller. I'm thinking about picking this up just to get my feet wet. How would you feel about modifying the original suggestion slightly to more closely monkey how MDN formats their docs? I'm a big fan of stealing from the best. Something like this: ### Syntax
```
m(selector[, attrs[, ...children]])
```
#### Parameters
- `selector`
A component or [simple CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#Simple_selectors) string.
- `attrs` | _optional_
A key/value map of HTML attributes, element properties, and/or [lifecycle methods](https://mithril.js.org/hyperscript.html#lifecycle-methods).
- `children` | _optional_
A list of vnode children, including strings, numbers, vnodes, or arrays of vnode children. `null`, `undefined`, and `false` represent holes.
#### Return value
A hyperscript vnode for Mithril to later [render](https://mithril.js.org/render.html).
[*How to read signatures*](https://mithril.js.org/signatures.md) And rendered:
I think this could offer a few advantages:
|
IMO the original proposal works for most stuff, but The MDN style for XHR is of a similar length to |
@orbitbot We could hide the bullet points by just wrapping the signature in a As for TS-like vs MDN, I'm neutral. I personally prefer to avoid explicit type names, sticking a little closer to MDN with a few TS/ES things like And MDN's use of Something aligned with what jQuery does would look like this: `m(selector [, attrs] [, child1] [, childN])`
*Returns: a [vnode](vnodes.md#structure)`*
- `selector`<br>
Type: String or Object<br>
A CSS selector or a [component](components.md)
- `attrs`<br>
Type: Object<br>
HTML attributes or element properties
- `child1`<br>
Type: String, Number, Boolean, a vnode, or an array of children<br>
A child [vnode](vnodes.md#structure).
- `childN`<br>
Type: String, Number, Boolean, a vnode, or an array of children<br>
Additional child [vnodes](vnodes.md#structure).
[How to read signatures](signatures.md) Rendered:
|
To be clear, my issue with the documentation in the case of something like the amount of options that Without proper spacing for the "wall of bullet points", it's essentially like reading a long text without typography, where indentation and line breaks between paragraphs have been removed. I don't really have that much issue with MDN or jQuery style, other than that with a lot of options it starts to consume so much vertical space that the reader might lose the context. Not sure how relevant the subheadings are in MDN's XHR docs, but I don't really keep track of what section I'm reading, and this is with zooming out (Chrome's site zooming) a bit so I still have more vertical space visible. |
If the parameter description is in its own paragraph, it gives you room to inline a type annotation if you wanted to include it:
Though it might be clearer with a JSDoc style annotation:
A few ways to include an optional tag with an inline type too:
As for the function signature itself, I think the use of brackets to denote optional parameters is really common and worth replicating. Not really particular on whether those are nested (MDN), sequential (jQuery) or whatever. I don't think trying to make the signature more JS-like (as in the original suggestion) is a great approach. It's not really valid JS as written anyway. So I would personally rather have some good example code which is 100% valid, best-practice, JS, and then something distinct but clear which documents the signature. |
Currently, we use a relatively unusual signature mechanism to document how our functions are called. It's nice and concise for a few simple cases, but it has a habit of getting in the way of readability and accuracy in the more complicated scenarios:
m.request
, the description gets hard-to-read in a hurry. Also,m.request
'surl
parameter is somewhat inaccurate.m
, the signature doesn't properly encapsulate reality without a lot of prose.m.route(root, defaultRoute, routes)
, the longObject<...>
moves all the useful information far into the right.m.route.set(route, params, options)
, the longoptions.state
description should really be broken out, but it's unclear where it should go with the current signature mechanism. There's quite a few other instances where things are in the signature, yet don't belong there, such asrouteResolver.onmatch
'srequestedPath
parameter andm.request
'soptions.extract
m.route.link(vnode)
/m.route.link(opts)
, our signature mechanism just complicates documenting it.I've only covered about a third of the signatures in links above, and only individual bits of them in the bulleted list. But if you actually look at how it renders, I'd estimate about half of them have issues generated from the signature format itself.
What I'm really proposing here is that we should change our signature format to be much more readable. I'm thinking of something like this, using
m()
as an example:Rendered:
For comparison, here's the existing docs:
Rendered:
I'm open to other ideas, like using TypeScript types, as long as they're an improvement over what we currently have.
In case you're curious how I'd change
m.request
, here's how I'd do that:Rendered:
For comparison, here's the original docs:
Rendered:
The text was updated successfully, but these errors were encountered: