Skip to content

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

Merged
merged 3 commits into from
May 13, 2019
Merged

Conversation

toji
Copy link
Member

@toji toji commented May 2, 2019

/Fixes #608

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.

@toji toji added this to the May 2019 milestone May 2, 2019
@toji toji requested a review from NellWaliczek May 2, 2019 21:53
@toji
Copy link
Member Author

toji commented May 2, 2019

@AdaRoseCannon: Is the magical /fixes syntax wired up for comments yet, and if so did I fail to invoke it properly above?

@Manishearth
Copy link
Contributor

live object that is updated in-place as input sources are added and removed.

I don't think this can be a FrozenArray in such a case. May need a new interface.

@toji
Copy link
Member Author

toji commented May 2, 2019

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.

@toji
Copy link
Member Author

toji commented May 2, 2019

At the very least The WebHID API thinks it's possible. :)

https://wicg.github.io/webhid/index.html#hidcollectioninfo

@Manishearth
Copy link
Contributor

A frozen array type is a parameterized type whose values are references to objects that hold a fixed length array of unmodifiable values. The values in the array are of type T.

I'm reading this as the array length being fixed from all sides, but the values can be internally modified (but not by users)

@toji
Copy link
Member Author

toji commented May 2, 2019

Ah, that might be right. That would be a meaningful limitation in this case.

@Manishearth
Copy link
Contributor

@heycam can you confirm my reading of how FrozenArray works?

@ddorwin
Copy link
Contributor

ddorwin commented May 2, 2019

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.

@heycam
Copy link

heycam commented May 3, 2019

That's right, FrozenArray<T> means a JS Array object that has been frozen in the same way that calling Object.freeze() does. So the values cannot cannot be changed, even by the engine.

https://heycam.github.io/webidl/#es-frozen-array

@Manishearth
Copy link
Contributor

Manishearth commented May 3, 2019

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)

@toji
Copy link
Member Author

toji commented May 3, 2019

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 XRInputSources themselves. I'll try to consult with @bfgeek about this as well to further evaluate the API ergonomics.

@Manishearth
Copy link
Contributor

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.

@toji
Copy link
Member Author

toji commented May 3, 2019

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.

@Manishearth
Copy link
Contributor

Manishearth commented May 3, 2019

I care about this more from the point of view that we should specify how an XRInputSource behaves when disconnected, without necessarily exposing this state to users.

e.g. does getPose() start failing on input spaces? is it frozen? can it be either? (per-device / up to implementor)

@AdaRoseCannon
Copy link
Member

@toji it's /fixes with a lower case f

@AdaRoseCannon
Copy link
Member

/fixes #608

@AdaRoseCannon AdaRoseCannon added fixed by pending PR A PR that is in review will resolve this issue. and removed fixed by pending PR A PR that is in review will resolve this issue. labels May 8, 2019
@AdaRoseCannon AdaRoseCannon removed their assignment May 8, 2019
@toji
Copy link
Member Author

toji commented May 8, 2019

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.

@Manishearth
Copy link
Contributor

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 getInputSources() again if you want it updated)

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 iterable)

@toji
Copy link
Member Author

toji commented May 8, 2019

Here's an example of a more recent API that does use iterable: https://drafts.css-houdini.org/css-typed-om/#cssnumericarray

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.
@toji toji force-pushed the input-sources-attrib branch from 64de337 to 3f65662 Compare May 10, 2019 19:35
@toji
Copy link
Member Author

toji commented May 10, 2019

Updated this PR to make use of iterable. I'm pretty happy with this approach, but would be interested to hear if there were any concerns about going this route.

Copy link
Member

@NellWaliczek NellWaliczek left a 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!

@@ -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.
Copy link
Member

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.

@toji toji merged commit 393984a into master May 13, 2019
@AdaRoseCannon AdaRoseCannon added ed:explainer Include in newsletter, explainer change ed:spec Include in newsletter, spec change labels Jun 17, 2019
@toji toji deleted the input-sources-attrib branch July 2, 2019 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ed:explainer Include in newsletter, explainer change ed:spec Include in newsletter, spec change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify live-ness of XRInputSources
6 participants