Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Feature detection is somewhat weird #18

Closed
sicking opened this issue Apr 14, 2016 · 6 comments
Closed

Feature detection is somewhat weird #18

sicking opened this issue Apr 14, 2016 · 6 comments
Labels

Comments

@sicking
Copy link

sicking commented Apr 14, 2016

I don't feel strongly here, but the way the feature detection works is pretty unusual. This pattern appears nowhere else in the web platform.

Not a huge deal in and of itself, but at least warrants some discussion on the mailing list to see if there's existing patterns that can be reused.

One somewhat unfortunate aspect of how it currently works is that you have to get access to an IDBDatabase or IDBTransaction object before you can do feature detection. That makes it hard for a library to do detection when the library is first loaded.

It might be better to stick a static function somewhere instead.

@dmurph
Copy link
Collaborator

dmurph commented Apr 18, 2016

I talked with Josh (@inexorabletash), and he mentioned that he remembered how some other features are detected on the web platform:

Calls with options return an object with those options populated, so the developer can check to see which options that the specified were reproduced in returned options. This can also help with option modes, where a browser only supports mode A and I want B. When I specify B, I can check the options returned and see that A is there, so the browser only supports A.

Not the best, especially because i requires the IDB* objects like you mentioned. I'd be open to a static function. WDYT josh?

dmurph added a commit that referenced this issue Apr 18, 2016
Addressing issues #22, #19, #17, and #18.

* Removed event version
* Made `storeOptions` definitely a Map
* Changed feature detection model to including a parsed and validated `options` object in the control object.
* Removed old initialization mode comment.
dmurph added a commit that referenced this issue Apr 18, 2016
Added feature detection object added some comments.
#23, #20, #19, #18
@inexorabletash
Copy link
Member

Hrm, that's not quite what I was envisioning. Generally options would end up exposed as readonly attributes on the object they represent - I wouldn't introduce a separate objects for that.

So mechanically:

interface IDBObserverControl {
  readonly attribute IDBDatabase db;
  readonly attribute boolean transaction; // reflects option
  readonly attribute boolean onlyExternal; // reflects option
};

// Maybe change this to an interface?
dictionary IDBObserverChanges {
  IDBDatabase db;
  IDBTransaction transaction;
  boolean value; // reflects option
  boolean noRecords; // reflects option
  sequence<IDBKeyRange> ranges; // reflects option
  any records;
};

... but that points out that the names of some of these could use tweaking (e.g. plural for value vs. noRecords). Also, the feature detection can be done for many of these simply by the lack of data in the response e.g. if transaction is in the result dict, it is supported; similar for value and noRecords. So I'm not sure there's a huge value in most of these. onlyExternal makes sense, as does including the ranges.

Aside: Should db attributes/dictionary members be spelled connection instead?

@sicking
Copy link
Author

sicking commented Apr 18, 2016

Another approach that we could take here is to look for a genric mechanism for feature-detecting dictionaries and enums.

I.e. right now it's generally easy to detect support for features that live on WebIDL interfaces by looking at window.InterfaceName.featureName. However this is not true when a feature lives as a property on a dictionary or as a value in an enum.

We could define something like window.dictionaries.DictionaryName.featureName and window.enums.EnumName.enumValue.

I'm curious how JS libraries deal with this. It seems like this is going to become a more common problem given that ES6 has added syntax sugar for allowing dictionary arguments.

@domenic might know or have an opinion.

Generally speaking, I don't have an opinion here at all, as long as whatever we do has been vetted by enough people that we don't have to redo it.

@domenic
Copy link

domenic commented Apr 18, 2016

Sounds like whatwg/webidl#107

@dmurph
Copy link
Collaborator

dmurph commented Apr 20, 2016

I'm going to delete the feature detection parts of the description and IDL, and we can figure that out later.

dmurph added a commit that referenced this issue Apr 20, 2016
dmurph added a commit that referenced this issue Apr 20, 2016
@sicking
Copy link
Author

sicking commented Apr 20, 2016

Sounds good to me. Hopefully WebIDL will grow a generic solution.

@dmurph dmurph added the wontfix label Sep 29, 2016
@dmurph dmurph closed this as completed Jul 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants