WICG / webusb

Connecting hardware to the web.
https://wicg.github.io/webusb/
Other
1.31k stars 131 forks source link

What does "sequence" in the draft refer to? #69

Closed karelbilek closed 7 years ago

karelbilek commented 7 years ago

I am trying to understand the draft and I don't understand the exact meaning of the word "sequence". For example

dictionary USBDeviceRequestOptions {
  required sequence<USBDeviceFilter> filters;
};

What does it mean? Does it have to be an Array?

This might be a wider Javascript thing that I don't get. I just cannot google anything on the web about this.

reillyeon commented 7 years ago

Sequence is a WebIDL type that is mapped to Array in ECMAScript.

If I'm reading the WebIDL specification correctly then you can pass any iterable thing where a sequence is expected.

karelbilek commented 7 years ago

I am now writing a definition file for WebUSB for Flow typing system, so I want to know if I can write sequence<x> as Array<x> or if I have to write something like Iterable<x>.

So far it seems like Array<x> is fine.

reillyeon commented 7 years ago

It looks like someone has written a tool to automatically generate Flow definitions from WebIDL and they map sequence to Array:

https://www.npmjs.com/package/webidl-tools

karelbilek commented 7 years ago

Thanks for that! I was rewriting that by hand :)