Re: [heycam/webidl] Need pattern for feature detecting dictionary members (#107)

@domenic: Yeah I find it aesthetically much nicer to ask a feature-detect question of the *API* not the dictionary object. I would rather avoid polluting the global namespace with dictionary names just for this purpose.

On `navigator.share` I was leaning more towards adding a separate `canShare` method rather than expose the dictionary. Having a standard `supports` "sub-method" would help avoid polluting the namespace with `canX` methods.

> The limitation of this is that it assumes a single dictionary argument.

If we're going with this approach, I don't see why we would bother tying it to the dictionary at all, or restricting it to dictionary-taking methods. Why not just say certain methods have a "`supports`" sub-method that takes a single string and returns a Boolean indicating whether that feature is supported. I'm not sure why this "imageOrientation" example has a second argument (what "none" means).

This could be formalized in IDL like this (strawman syntax):

```webidl
partial interface Navigator {
    [SecureContext, SupportsFeatures<"image", "video">] Promise<void> share(ShareData data);
};
```

The presence of SupportsFeatures indicates that share.supports exists, and the feature list inside shows what strings are valid arguments to the supports method.

@RByers suggestion works for me also: this generalizes to "the `supports` method takes exactly the same arguments as the base method, has no side-effect, and returns `true` if it notionally would accept that argument". For example, you could write:

```js
canvas.toBlob(blob => {
  let sharedata = {title: 'My painting', image: blob};
  if (!navigator.share.supports(sharedata)) {
    // error
  }
  navigator.share(sharedata);
}
```

So you just call `supports` with the same argument you would then pass to the API. The downside of this is: how do we communicate "partial support"; for example, a UA that doesn't support sharing images won't fail if it gets a ShareData with a title and image, it'll just share the title. So should `navigator.share.supports` on a non-image-supporting UA return `false` if given a title and image, even though it would still partially succeed? Perhaps it's best if I can directly ask the API "do you support image sharing"?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/107#issuecomment-303919253

Received on Thursday, 25 May 2017 04:28:19 UTC