Open
Description
JavaScript has the notion of Iterators and Generators, which allow sequential generation and access to elements in a collection without exposing the collection's internal structure.
Some links:
function*
syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*- Generator type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator
- Iterator protocol: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol
Currently, generating interop for a Generator function would require having to:
- Create an extension type for the
Generator
type - Write JS interop for the generator function, and possibly lose out on the powerful features it has
This issue aims to address at least one of the following:
- Adding support for a
JSGenerator
andJSIterator
type: This issue proposes the addition of theJSGenerator
extension type and aJSIterator
extension type (JSGenerator
builds on top of, and extendsJSIterator
). This allows for not having to unnecessarily reimplement global JS types in different codebases. Instead, it would be better if they were core types in the Dart JS Interop library. Even ifJSGenerator
isn't viable, having aJSIterator
type can help, especially when users may want to use such iterators fromJSArray
. - Add support for mapping JS Generator Functions to Dart Generator Functions: Dart also has a similar notion of Generator functions through the use of
sync*
andasync*
mapped withyield
and/oryield*
It would be nice if Generator functions could be mapped from JS to Dart Generator functions (similar to how asynchronous functions in JS are mapped to Dart asynchronous functions). This can help for users to be able to leverage Dart's sound typing when needed (mapping the iterator type in Dart toIterable<String> list() sync* { for (var i = 0; i < 4; i++) { yield i.toString(); } }
JSIterator
, for instance), and still be able to fall back to JS's way of doing things if they want
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status