Skip to content
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

docs: define practices for third-party extensible APIs #586

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions wg-api/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ function whatever(opts: { a: string, b?: boolean }) { /* ... */ }

See https://w3ctag.github.io/design-principles/#prefer-dict-to-bool for more details.

### Should the configured options be made extensible to third-party libraries?

If an API accepts configuring options, should it provide the ability to append to rather than replace those options?
Would third-party libraries require special attention to API usage to avoid clobbering configured options?
samuelmaddock marked this conversation as resolved.
Show resolved Hide resolved

See the [style guide for designing APIs when dealing with arrays.](#provide-createreadupdatedelete-options-when-dealing-with-arrays)

### What underlying Chromium or OS features does this API rely on?

If the API you’re changing relies on underlying features provided by Chromium or by the operating system, how stable are those underlying features? How might those underlying features change in the future?
Expand Down Expand Up @@ -134,6 +141,26 @@ Even if seconds (or some other time unit) are more natural in the domain of an A

See https://w3ctag.github.io/design-principles/#milliseconds

### Provide create/read/update/delete options when dealing with arrays

If an API is designed to accept an array of items, consider providing methods of creating, reading, updating, and deleting items.

In the case of third-party libraries, one might want to add a single item rather than replacing existings items.

```js
// Bad: third-party libraries can only replace registered schemes
protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { standard: true } }
])

// Good: third-party libraries can create, read, update, and delete items
if (protocol.getRegisteredSchemes().includes(scheme => scheme.scheme === 'app')) {
protocol.unregisterScheme({ scheme: 'app' })
}
protocol.registerScheme({ scheme: 'app', privileges: { standard: true } })
protocol.updateScheme({ scheme: 'app', privileges: { secure: true } })
samuelmaddock marked this conversation as resolved.
Show resolved Hide resolved
```

## Classes

### Use a class's name as the module name
Expand Down