Skip to content

Commit

Permalink
Add a guideline for mixins (#9016)
Browse files Browse the repository at this point in the history
* Add a guideline for mixins

* Apply suggestions from code review

Co-authored-by: Daniel D. Beck <daniel@ddbeck.com>

* Update docs/data-guidelines.md

Co-authored-by: Philip Jägenstedt <philip@foolip.org>

* Fix code block

Co-authored-by: Daniel D. Beck <daniel@ddbeck.com>
Co-authored-by: Philip Jägenstedt <philip@foolip.org>
  • Loading branch information
3 people committed Feb 11, 2021
1 parent f2f1057 commit bee9ac1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/data-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This file contains recommendations to help you record data in a consistent and u
- [Removal of irrelevant features](#removal-of-irrelevant-features)
- [Removal of irrelevant flag data](#removal-of-irrelevant-flag-data)
- [Initial versions for browsers](#initial-versions-for-browsers)
- [Mixins](#mixins)

<!-- BEGIN TEMPLATE
Expand Down Expand Up @@ -256,3 +257,26 @@ If the table indicates an initial version of "1" and an information source says
If you're adding new data for Node.js, use `0.10.0` or later. If a feature was added in a version before `0.10.0`, use `0.10.0` anyway.

This guideline was proposed in [#6861](https://github.com/mdn/browser-compat-data/pull/6861).

## Mixins

[Interface mixins](https://heycam.github.io/webidl/#idl-interface-mixins) in Web IDL are used in specifications to define Web APIs. For web developers, they aren't observable directly; they act as helpers to avoid repeating API definitions. Don't add mixins to BCD where they do not already exist.

For example, [`HTMLHyperlinkElementUtils`](https://html.spec.whatwg.org/multipage/links.html#htmlhyperlinkelementutils) is a mixin defined in the HTML specification.

Members of this mixin are available to `HTMLAnchorElement` and `HTMLAreaElement`, that's where BCD exposes them. Add mixin members to BCD in one of these ways:

1. For smaller mixins, add members of `HTMLHyperlinkElementUtils` directly to the `api/HTMLAnchorElement.json` and `api/HTMLAreaElement.json` files as if they were regular members of these interfaces.

2. For larger mixins, create a file in the `api/_mixins/` folder and indicate for which interface they are using file names like: `HTMLHyperlinkElementUtils__HTMLAnchorElement.json` and `HTMLHyperlinkElementUtils__HTMLAreaElement.json`.
In these files, expose the data under the correct tree. For `HTMLHyperlinkElementUtils__HTMLAnchorElement.json`, the file needs to start like this:

```
{
"api": {
"HTMLAnchorElement": {
"myFeatureName": {
"__compat": {
```

This guideline was proposed in [#8929](https://github.com/mdn/browser-compat-data/issues/8929), based in part on previous discussion in [#472](https://github.com/mdn/browser-compat-data/issues/472).

0 comments on commit bee9ac1

Please sign in to comment.