RE: What does it all hang off of?

My opinion about this issue: it should hang off of navigator.platform or better yet: just platform. Hanging it off of navigator implies that Contacts actually are associated with the browser, which they are not. They are associated with the platform.  

Hence, platform.contacts.findOne().

My second choice would be to hang contacts off of device, like #4 below.

-----Original Message-----
From: public-device-apis-request@w3.org [mailto:public-device-apis-request@w3.org] On Behalf Of Robin Berjon
Sent: Friday, October 02, 2009 05:33 AM
To: public-device-apis@w3.org
Subject: What does it all hang off of?

Hi all,

one issue we have with APIs is also how they are exposed. Say for  
instance that the Contacts API has a basic interface providing access  
to the rest of the functionality called "Contacts". We could:

1) Make it available as a constructor:

   var cs = new Contacts();
   var mum = cs.findOne({ nickname: "mum" });

This pollutes the global namespace (since "Contacts" is now a variable  
in that scope), and is useless since there's no use for multiple  
instantiation of that class.

2) Make it available as an object already instantiated in the global  
scope:

   var mum = contacts.findOne({ nickname: "mum" });

This is nicer, less useless, but still polluting. Given the number of  
APIs that we have, it's probably a bad idea.

3) Make a way of requesting that an API be "loaded":

   var mum = loadAPI("contacts").findOne({ nickname: "mum" });

This adds only one item to the global scope (which is acceptable), but  
isn't idiomatic.

4) Use an object to provide access to all the device APIs:

   var mum = device.contacts.findOne({ nickname: "mum" });

I think the latter is the cleanest option. Specifying one such  
extensible object is trivial, and would be a very short specification.

Another option is to hang off of the navigator object just like  
geolocation did - but that seems wrong (I'm not sure why it was chosen  
there).

Thoughts?

-- 
Robin Berjon - http://berjon.com/

Received on Friday, 2 October 2009 17:47:15 UTC