contact-picker icon indicating copy to clipboard operation
contact-picker copied to clipboard

Consider dictionaries and sequences instead of non-constructible interfaces and frozen arrays

Open domenic opened this issue 6 years ago • 3 comments

Since they are only used in a return value, using mutable data structures would be more developer friendly.

domenic avatar Nov 13 '18 21:11 domenic

It didn't feel very common for APIs to return (sequences of) dictionaries, but I agree that there's little value in having interfaces. Does https://github.com/beverloo/contact-api/compare/dictionaries make sense to you?

The one argument against this is that it makes feature detection of particular properties harder. Does Browser A support telephone numbers? That's worth considering since it's a non-goal to expose all information stored in a contact.

beverloo avatar Nov 14 '18 15:11 beverloo

Looks pretty good. Note however that you no longer need nullability; dictionary entries are optional by default. And it's more idiomatic to leave those properties un-set than it is to create the properties but set their values to null.

As for feature detection, I guess I don't quite understand. Even in the interface version, having the IDL attribute implemented doesn't necessarily mean the browser is going to expose that information.

domenic avatar Nov 14 '18 16:11 domenic

That's much nicer indeed - thanks!

Regarding feature detection, a developer would be able to know whether telephone numbers are supported by checking whether ContactInfo.prototype.tel exists. That's something we lose with a dictionary, but that may be OK as select() will throw a TypeError for invalid values of the ContactProperty enum.

beverloo avatar Jan 23 '19 15:01 beverloo