-
Notifications
You must be signed in to change notification settings - Fork 161
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
Formalizing domintro typography, etc. #190
Comments
Yes to this issue. Not sure of the best way to make progress on each line item... Agree with the "easy" ones where @domenic expresses an opinion. Re: getters - Re: omit Re: statements vs. expressions - well, we don't require semicolons, so +1 to "say domintros use expression syntax" Re: When do we prefix APIs with Re: options dictionaries - https://wicg.github.io/web-locks/#api-lock-manager-request is another example which calls out the options in a more documentation-like way using a nested <dl>, rather than object literal syntax. In contrast, the Re: optional args - yes, |
Bikeshed could maybe help with formatting and linking if we follow a strict template? cc @tabatkins |
Agreed. Ideally, as much as possible would be linked to their IDL types, such as the method name, the args, the return value.
I'd be happy to follow some agreed set of https://prettier.io/playground/ rules.
I find it confusing to read fwiw.
I use them in code, but no strong feelings here. Again, happy with some Prettier rules.
Agreed.
const thing = new Thing();
for await (const thing of iterable) { /* … */ }
Don't think it needs a var.
Two separate pairs I reckon.
Agree with
Happy with Prettier rules for spacing.
Yeah, and the resulting var should link to the IDL type.
I'd prefer one of var/let/const, just so it looks like good practice.
Using destructuring if the return type is a dictionary seems ok. Again it'd be great if they link to their types. I agree it should have var/let/const.
Fwiw, I suggested this set of rules for MDN but I don't think they did anything with it:
If something is only available in a particular context, I wonder if we can come up with a visual 'tag' of sorts.
I like I like 'destructuring' for option objects too:
|
Here's a halfway point that tries to decide the easy stuff. I might do a pass on HTML to try to uniformize things and gather examples to help with the harder stuff. Decisions
Not yet decided
Canonical examplesGetter-only properties: <dt><code><var>event</var>.<a href="...">bubbles</a></code>
<dd>Returns ... reference <var>event</var> ... Getter/setter properties: <dt><code><var>title</var>.<a href="...">text</a></code>
<dd>Returns ... reference <var>title</var> ...
<dt><code><var>title</var>.<a href="...">text</a> = <var>value</var></code>
<dd>... reference <var>title</var> and <var>value</var> ... Undefined-returning methods: <dt><code><var>table</var>.<a href="...">deleteCaption</a>()</code>
<dd>... reference <var>table</var> ... Non-optional argument taking methods: <dt><code><var>table</var>.<a href="...">deleteRow</a>(<var>index</var>)</code>
<dd>... reference <var>table</var> and <var>index</var> ... Value-returning methods: <dt><code><var>tfoot</var> = <var>table</var>.<a href="...">createTFoot</a>()</code>
<dd>... reference <var>table</var>, maybe reference <var>tfoot</var> ... Varargs methods: <dt><code><var>node</var>.<a href="...">append</a>(...<var>nodes</var>)</a></code>
<dd>... reference <var>node</var> and <var>nodes</var> ...</dd> Constructors: <dt><code><var>document</var> = new <a href="...">Document</a>()</code>
<dd>Constructs ...</dd> Promise-for-undefined returning methods: <dt><code>await <var>image</var>.<a href="...">decode</a>()</code>
<dd>Causes ..., returning a promise that fulfills when... The promise will be rejected when...</dd> <!-- or similar --> Promise-for-value returning methods: <dt><code><var>constructor</var> = await <var>customElements</var>.<a href="...">whenDefined</a>(<var>name</var>)</code>
<dd>Returns a promise that will be fulfilled with... The promise will be rejected if... reference <var>name</var>...</dd> (note: customElements is not final and is subject to the outstanding "base" debate.) |
Re: optional args The MDN style guide on this lists out the permutations as multiple lines. There's a "Formal Syntax" section as well, but that would not be relevant for domintro. There was recent discussion leading to this. |
Potentially, tho it looks like there's a pretty wide set of variations here that would make it difficult, with vars in different places and multi-level dot-access (so I can't reasonably infer the Going thru Domenic's set of canonical examples and trying out some possible microsyntaxes, it's not gaining much, and doesn't meaningfully restrict what is put in there, either. Tho, hm, perhaps a more expansive set of microsyntaxes (rather than trying to handle everything in one) could work...
Like @jakearchibald, I find the spaces around The best I can see for a markup shorthand is: Getter-only properties:
Getter/setter properties:
Undefined-returning methods:
Non-optional argument taking methods:
Value-returning methods:
Varargs methods:
Constructors:
Promise-for-undefined returning methods:
Promise-for-value returning methods:
(both of these would throw a Bikeshed error if Dunno if this is worthwhile. |
If Bikeshed supports |
Are there any examples of domintro blocks describing EventHandlers? (I didn't spot any in a quick check.) Should we have them? |
We have the event-handler index at https://html.spec.whatwg.org/multipage/indices.html#ix-event-handlers And there are a few others at places like https://html.spec.whatwg.org/multipage/media.html#cue-events in the body of the spec. Whether documenting them that way is better or worse for developer usability than having domintro blocks for them, I dunno. |
This implements some of the changes described in whatwg/meta#190 (comment) for our "For web developers (non-normative)" boxes, i.e. "domintro" boxes. Although the first three domintros were rewritten by hand and thus reflect all of those changes, the rest were transformed in an automated fashion, with only the following transformations applied: * Wrap the entire line in <code> instead of just some property names. * Remove spaces around dots and parentheses. * Move ...s before the argument, like JavaScript, instead of after. Additionally the nature of the automated process involved rewrapping all the <dd> contents, and *un*wrapping all <dt> contents. Some linebreaks were removed and inserted as well to give a consistent style.
Aligns better with whatwg/meta#190 (comment).
* Introduces internal slots for "binary type" and "ready state" * Uses "method steps"/"getter steps"/"setter steps" uniformly * Updates domintro to more closely follow the conventions discussed in whatwg/meta#190 (comment)
* Introduces internal slots for "binary type" and "ready state" * Uses "method steps"/"getter steps"/"setter steps" uniformly * Updates domintro to more closely follow the conventions discussed in whatwg/meta#190 (comment)
This implements some of the changes described in whatwg/meta#190 (comment) for our "For web developers (non-normative)" boxes, i.e. "domintro" boxes. Although the first three domintros were rewritten by hand and thus reflect all of those changes, the rest were transformed in an automated fashion, with only the following transformations applied: * Wrap the entire line in <code> instead of just some property names. * Remove spaces around dots and parentheses. * Move ...s before the argument, like JavaScript, instead of after. Additionally the nature of the automated process involved rewrapping all the <dd> contents, and *un*wrapping all <dt> contents. Some linebreaks were removed and inserted as well to give a consistent style.
It'd be nice to get some consistency in the "domintro" boxes for specs. By those I mean the green "For web developers (non-normative)" boxes like in:
Easy-ish issues worth thinking about:
Typography. I prefer making everything inside the
<code>
block, with nested<var>
s inside for things that would be variable in JavaScript. HTML does not do this, but most other specs seem to, most of the time.Spacing around method/constructor-call parentheses. HTML seems to be pretty inconsistent. Most other specs have no spaces, like idiomatic JavaScript code.
Spacing around
.
s. Everyone seems to add spaces, even though it's not idiomatic JavaScript. Probably worth keeping; it's a nice visual separator.Semicolon usage. I noticed one, but probably we shouldn't.
Promise-returning methods. I like using
await
syntax with these.Making sure we settle on conventions for things like constructors, (async) iterators, etc.
Getters. Do we do
value = interface . prop
? Justinterface . prop
?semanticName = interface . prop
, like Stream'sisLocked = stream . locked
? This seems very inconsistent across and within specs.Setters in combination with getters. We seem to do
interface . prop [ = value ]
. An alternative would be two<dt>
s, one for the setter and one for the getter. Or just two entirely separate<dt>
/<dd>
pairs.Varargs currently use the syntax
[arguments...]
(see below on the brackets). Should we align with JavaScript and use...arguments
or similar? See setTimeout/setInterval.Spacing around parameter lists, optional arguments (see below), etc.
Medium-difficulty issues worth thinking about:
Return values from methods. Undefined-returning methods can be written simply, but should methods that return something be written with their return values shown? Probably yes.
But is it OK to omit the leading
var
/let
/const
? We have so far (mostly)What about in cases of destructuring, e.g.
{ database, store, version } = storage.backingStore
from KV Storage, or[branch1, branch2] = stream.tee()
from Streams? Those aren't valid JS statements; you'd need to either add the leadingvar
/let
/const
, or wrap the whole expression in parentheses. Maybe that's fine and we just say domintros use expression syntax?When do we prefix APIs with
window .
orself .
? And if we do, should we treat them as variables (i.e., documenting that these APIs work on anyWindow
or anyWindowOrWorkerGlobalScope
)? Or should we treat them as global properties, since that's the 99% use case? E.g.:HTML does
window . history . length
, andwindow . document
(note the<var>
s aroundwindow
, indicating that it can be used with anyWindow
instance.But it does
self . navigator . onLine
, which is a bit strange; usingself
as a variable isn't something you'd expect. MaybewindowOrWorkerGlobalScope . navigator . onLine
, but that's gross.Most
Navigator
properties are prefixed withself . navigator .
, but the Window-only ones are prefixed withwindow . navigator .
. So although it might feel like the leading object is redundant, in this case it's valuable?Elsewhere HTML does
self . origin
with no variable.Elsewhere it does
location . hash
, which I guess is reasonable since multiplelocation
objects are accessible. But why no leadingwindow
?No other specs seem to use the leading
window .
orself .
.Harder issues worth thinking about:
Optional arguments. We use syntax like
interface . method(foo [ , bar ])
. This is OK-ish, but for single optional arguments (like in Streams'sstream.cancel([ reason ])
, it looks like we're passing an array. Can we do better?"Objet literal syntax" for options arguments. This is probably best left to editor discretion, but perhaps we can come up with some guidelines. Compare the various methods Streams links above. Things to note:
In
new ReadableStream(underlingSource[, strategy])
,underlyingSource
andstrategy
are both dictionaries. However, they are first-class concepts, so I left them as variables instead of expanding them.I have two separate entries for
stream.getReader()
andstream.getReader({ mode: "byob" })
, since they behave pretty differently, despite the IDL beingoptional ReadableStreamGetReaderOptions options = {}
.I did not add optionality brackets to any of the dictionary members in
stream.pipeTo(destination[, { preventClose, preventAbort, preventCancel, signal }])
, despite them all being optional. It would have gotten pretty unwieldy.I did not add values for the dictionary members in
pipeTo()
, even though for the booleans at least, it might have been reasonable. Contrast withstream.getReader({ mode: "byob" })
, where I did./cc @whatwg/documentation
The text was updated successfully, but these errors were encountered: