Skip to content

Add 'Choose the Appropriate WebIDL Construct for Data and Behavior' #567

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

marcoscaceres
Copy link
Contributor

@marcoscaceres marcoscaceres commented Mar 25, 2025

Initial text to picking the right thing...


Preview | Diff

Copy link
Contributor

@martinthomson martinthomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use <div class=example more.

Copy link
Contributor

@martinthomson martinthomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots more typos to fix throughout, but concentrating on high-level stuff.

@@ -1524,6 +1524,132 @@ the interaction with garbage collection.

<h2 id="api-surface">JavaScript API Surface Concerns</h2>

<h3>Choose the Appropriate WebIDL Construct for Data and Behavior (Dictionaries, Interfaces, and Namespaces)</h3>

Web APIs commonly pass around data and functionality using WebIDL. As a specification author, decide carefully whether
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally go with something more direct for this first paragraph/sentence of each principle.

}
```

If the interface can holds data that is useful when serialized (e.g., `GeolocationPosition`), consider adding a `toJSON()` default method. Alternatively, if it holds binary data, one can add .toBlob() an so on.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this toJSON() thing something that belongs here? Or is it a distraction?

Comment on lines +1624 to +1629
If warrented by the use cases, give the interface a constructor. Be mindful to not just add a constructor if a class has no state. Doing so is considered by practice by effectively creaeting a fake class.
(see `DOMParser` or `DOMImplementation` as bad examples).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a different principle again?


Each construct has its own pros and cons, discussed below.

<h4>Use Dictionaries for “Configuration” or “Input-Only” Data</h4>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later sections use something like this:

<h4 id="static-objects" class="no-num no-toc">Static objects</h4>

Consider following that example.

@jyasskin
Copy link
Contributor

Is this meant to close #11?

@jyasskin jyasskin force-pushed the interfaces-dicts-namespaces branch from f982070 to d27fcae Compare May 2, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants