XR.requestSession() and XRSession.requestReferenceSpace() both take a single options parameter. In many/most cases, only a single primary value from the options needs to be specified. It may be better to instead specify that primary value separately followed by an optional options parameter. This may both simplify the current API and allow for more flexibility for future extension.
Consider:
- The pair of methods in the
XR interface are intended to be used together but do not share parameter types:
Promise<void> supportsSessionMode(XRSessionMode mode);
Promise<XRSession> requestSession(optional XRSessionCreationOptions parameters);
XRReferenceSpaceOptions only contains a type and subtype.
- IDL methods can accept different types in the same parameter slot (i.e., https://heycam.github.io/webidl/#idl-union). If the primary value is a separate parameter, subsequent parameters can be different types rather than needing to have a union of all possible values used for any primary mode/type.
With that in mind, the two methods might be changed as follows:
Promise<XRSession> requestSession(XRSessionMode mode, optional XRSessionCreationOptions options);
- Note that one argument is now required. This is a minor part of the change, but it seems reasonable to expect the caller to specify the mode they want just as they do for
supportsSessionMode().
Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type);
XR.requestSession()andXRSession.requestReferenceSpace()both take a single options parameter. In many/most cases, only a single primary value from the options needs to be specified. It may be better to instead specify that primary value separately followed by an optional options parameter. This may both simplify the current API and allow for more flexibility for future extension.Consider:
XRinterface are intended to be used together but do not share parameter types:Promise<void> supportsSessionMode(XRSessionMode mode);Promise<XRSession> requestSession(optional XRSessionCreationOptions parameters);XRReferenceSpaceOptionsonly contains atypeandsubtype.With that in mind, the two methods might be changed as follows:
Promise<XRSession> requestSession(XRSessionMode mode, optional XRSessionCreationOptions options);supportsSessionMode().Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type);