Skip to content

[dart:js_interop] Support Generators and IteratorsΒ #60457

Open
@nikeokoronkwo

Description

@nikeokoronkwo

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:

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 and JSIterator type: This issue proposes the addition of the JSGenerator extension type and a JSIterator extension type (JSGenerator builds on top of, and extends JSIterator). 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 if JSGenerator isn't viable, having a JSIterator type can help, especially when users may want to use such iterators from JSArray.
  • 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* and async* mapped with yield and/or yield*
    Iterable<String> list() sync* {
      for (var i = 0; i < 4; i++) {
        yield i.toString();
      }
    }
    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 to JSIterator, for instance), and still be able to fall back to JS's way of doing things if they want

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions