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

Proposal: A new way to do feature detection for members #1181

Open
beaufortfrancois opened this issue Apr 3, 2023 · 3 comments
Open

Proposal: A new way to do feature detection for members #1181

beaufortfrancois opened this issue Apr 3, 2023 · 3 comments

Comments

@beaufortfrancois
Copy link

Web APIs are relying more and more on dictionaries. And doing feature detection of such members requires ugly and unnecessary complicated code. Following WICG/EventListenerOptions#31, #491, and many more over the years, I'm proposing WebIDL allows us to expose interfaces under a specific "namespace/scope" to avoid polluting the global scope.

Current state for an API called MyAPI

  1. A dictionary makes it unnecessarily hard to detect its members.
dictionary MyDictionaryOptions {
  boolean foo;
};
  1. An interface pollutes global scope as window.MyDictionaryOptions now unnecessarily exists.
[Exposed=Window]
interface MyDictionaryOptions {
  boolean foo;
}

Proposal

Use interfaces instead of dictionaries when possible and expose them under a specific member of the API.

[Exposed=Window.MyAPI] // <-- NEW!
interface MyDictionaryOptions {
  boolean foo;
}
if ("foo" in window.MyAPI.MyDictionaryOptions) {
  // 1. It's easy to detect foo exists in MyDictionaryOptions 
  // 2. Detecting it does not pollute global scope
  // 3. It does not require executing some methods to test it.
}

What do you folks think about this?

@annevk
Copy link
Member

annevk commented Apr 28, 2023

Why would we not continue the discussion in whatwg/webidl#107?

@eladalon1983
Copy link

eladalon1983 commented Apr 28, 2023

Why would we not continue the discussion in whatwg/webidl#107?

Do you mean to say that you'd like to conclude the discussion on whatwg/webidl#107 first? Or move the issues to that repo? Or that you would like François and I to both copy/paste our proposals into that specific thread as-is and continue there?

@annevk
Copy link
Member

annevk commented Apr 28, 2023

Primarily the first. And I recommend not focusing on specific solutions for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants