- From: Jonas Sicking <jonas@sicking.cc>
- Date: Fri, 22 Oct 2010 18:45:04 -0700
- To: Webapps WG <public-webapps@w3.org>
Hi all, IDBKeyRange is in need of some cleanup. The first issue is its constructors. Currently the IDL for IDBKeyRange, define that the constructors, .only, .leftBound, .rightBound, .bound, on object instances themselves. I don't think this is intentional since first of all it makes it impossible to create the first IDBKeyRange, second, second it seems strange to have constructor functions on instances. It seems like the intent is that the following should work: x = new IDBKeyRange.bound(...); and possibly also x = IDBKeyRange.bound(...); (the latter works for for example XMLHttpRequest, JS-heads have also informed me that it should work). Unfortunately there is no way to express this in WebIDL, so I think we need to describe it in prose instead. I'll raise this with Cameron, but I think that since at this point only IndexedDB uses these "static" functions, it might not make sense to add support to WebIDL. The other thing is that the .flags attribute is really not very javascript friendly as it uses bitfields. It also is weird in that it has multiple bits, but some have strong interdependencies. For example if SINGLE is set LEFT_OPEN and RIGHT_OPEN must be false, and LEFT_BOUND and RIGHT_BOUND must be true. It also seems like the LEFT_BOUND flag is closely correlated to the .left property. I suggest the following API instead: interface IDBKeyRange { readonly attribute any left; readonly attribute any right; readonly attribute boolean leftOpen; readonly attribute boolean rightOpen; }; the .left and .right properties return 'null' or 'undefined' (to be discussed) when the keyrange isn't bound in that direction. Another question I had is if "left" and "right" really are good names. Seems to me that "upper" and "lower" are better words, but it might be that left/right is established concepts in the database community? I don't feel strongly on this issue. Oh, I see now that bug 10397 is filed on this exact issue. Lastly, should we allow values to be passed directly to all APIs that currently take IDBKeyRanges? It seems nice to not require people to create an IDBKeyRange object using patterns like: req = objectStore.openCursor(new IDBKeyRange.only(foo)); and instead allow req = objectStore.openCursor(foo); Similarly, should we allow IDBObjectStore.get on and IDBIndex.get to take a IDBKeyRange and return the first value that matches the keyrange. This would allow things like "give me the first entry with a value greater than X". / Jonas
Received on Saturday, 23 October 2010 01:46:04 UTC