-
Notifications
You must be signed in to change notification settings - Fork 401
Change inputSources getter from method to attrib. #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@AdaRoseCannon: Is the magical /fixes syntax wired up for comments yet, and if so did I fail to invoke it properly above? |
I don't think this can be a FrozenArray in such a case. May need a new interface. |
My understanding was that FrozenArrays could be updated by the UA, and that the "frozen" aspect simply reflected that the developer couldn't alter it as they could other arrays, but that would be good to verify. |
At the very least The WebHID API thinks it's possible. :) |
I'm reading this as the array length being fixed from all sides, but the values can be internally modified (but not by users) |
Ah, that might be right. That would be a meaningful limitation in this case. |
@heycam can you confirm my reading of how FrozenArray works? |
I'm not sure what /Fixes is supposed to do, but if you put "Fix #..." in the summary, GitHub will automatically close the issue when the PR lands. I think this also causes a silent message in the issue that it is referenced by this PR. There are other syntaxes too. While not required, "Fix #abc: description" is a nice format. |
That's right, |
I guess we need a custom indexable/iterable interface here. (We can explicitly leave it undefined as to what the behavior is if the list of sources changes) |
Bleh. Thanks @heycam for the confirmation. I'd rather not get into defining new, custom sequence types in this spec. Perhaps simply leaving it as a getter method is the right move here, with some added clarity about the liveness of the |
Yeah, that feels best. It also fixes the iteration problem: when you call getInputSources you get a view into what the input sources were at the time, and you call it whenever you want an up to date view (maybe with an event handler for letting you know the list has changed) This does potentially mean that we need to add a "disconnected" state/event to XRInputSource and specify what it does when the source is disconnected. |
Possibly. I'm hesitant to add a connected/disconnected state simply because I've seen that it's been a fairly confusing thing for implementers and developers with the Gamepad API, but I'm not against it if has a clear benefit for developers and we can be really crisp about it's definition. |
I care about this more from the point of view that we should specify how an e.g. does getPose() start failing on input spaces? is it frozen? can it be either? (per-device / up to implementor) |
@toji it's /fixes with a lower case f |
/fixes #608 |
Consulted with @bfgeek about this and he clarified the "custom indexable/iterable interface" option that @Manishearth mentioned earlier and which I had misunderstood. (Sorry!) For those of you who, like me, were not familiar with the pattern it's something that apparently shows up semi-commonly in web specs and has well understood IDL semantics. Changing to a custom iterable type in our IDL would look something like this: interface XRInputSourceArray {
iterable<XRInputSource>;
readonly attribute unsigned long length;
getter XRInputSource(unsigned long index);
};
partial interface XRSession {
[SameObject] readonly attribute XRInputSourceArray inputSources;
} Which isn't quite as bad as what I had imagined. It's still not ideal to have to define the array type ourselves, but I can see that being a reasonable path here and would like feedback from other members on their preference. |
We might need to define how such an iterator gets invalidated or updated on input state changes. Presumably it's a frozen view over the input sources at the time it's fetched (call But yeah, this is more or less what I was suggesting. Kinda like HTMLCollection, but more up-to-date (HTMLCollection is legacy IIRC and may not use |
Here's an example of a more recent API that does use |
Changes the `getInputSources()` method on `XRSesssion` to a readonly attribute `inputSources`. This better reflects the expected behavior of the returned array being a live object that is updated in-place as input sources are added and removed.
64de337
to
3f65662
Compare
Updated this PR to make use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the due dilligence to make sure this was done right!
input-explainer.md
Outdated
@@ -31,10 +31,10 @@ In addition to a targeting ray, all input sources provide a mechanism for the us | |||
## Basic usage | |||
|
|||
### Enumerating input sources | |||
Calling the `getInputSources()` function on an `XRSession` will return a list of all `XRInputSource`s that the user agent considers active. The properties of an `XRInputSource` object are immutable. If a device can be manipulated in such a way that these properties can change, the `XRInputSource` will be removed from the array and a new entry created. | |||
The `inputSources` attribute on an `XRSession` will return a list of all `XRInputSource`s that the user agent considers active. The properties of an `XRInputSource` object are immutable. If a device can be manipulated in such a way that these properties can change, the `XRInputSource` will be removed from the array and a new entry created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will return
Slightly strange phrasing.
/Fixes #608
Changes the
getInputSources()
method onXRSesssion
to a readonlyattribute
inputSources
. This better reflects the expected behaviorof the returned array being a live object that is updated in-place as
input sources are added and removed.