Skip to content
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

Correct usage of Iterator and Iterable interfaces #1425

Closed
ma2ciek opened this issue Dec 21, 2018 · 3 comments
Closed

Correct usage of Iterator and Iterable interfaces #1425

ma2ciek opened this issue Dec 21, 2018 · 3 comments
Labels
resolution:expired This issue was closed due to lack of feedback. status:discussion status:stale type:docs This issue reports a task related to documentation (e.g. an idea for a guide).

Comments

@ma2ciek
Copy link
Contributor

ma2ciek commented Dec 21, 2018

As a follow-up to the #755 issue, we need to fix incorrect usages of these interfaces. If we go someday with the #1415 it will save us some time in fixing it anyway (TS is very accurate in the checking these interfaces). And it's easier to fix bugs in small PRs.

First of all, I'd redefine a little bit the rule that's in the #755 (comment).

  1. Use the Iterable interface for classes that implement the [Symbol.iterator]() method.

  2. Use the Iterable interface for function / method paremeter types. Unless you're sure that the function takes the Iterator (like the first( iterator ) function in ckeditor5-utils).

  3. Use the Iterable interface for generators. They implement actually the IterableIterator interface, but we don't use the code in such a way AFAIK, so it should be safe.

  4. Use the Iterator interface as a return type of the [Symbol.iterator]() method.

  5. Use the Iterator interface for custom iterators.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Dec 21, 2018

As an easy-to-remember way I'd go with TS interfaces:

interface Iterator<T> {
    next(value?: any): IteratorResult<T>;
    return?(value?: any): IteratorResult<T>;
    throw?(e?: any): IteratorResult<T>;
}

interface Iterable<T> {
    [Symbol.iterator](): Iterator<T>;
}

@Reinmar Reinmar added this to the backlog milestone Mar 25, 2019
@Reinmar Reinmar added the type:docs This issue reports a task related to documentation (e.g. an idea for a guide). label Mar 25, 2019
@pomek pomek removed this from the backlog milestone Feb 21, 2022
@CKEditorBot
Copy link
Collaborator

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

@CKEditorBot
Copy link
Collaborator

We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).

@CKEditorBot CKEditorBot added the resolution:expired This issue was closed due to lack of feedback. label Nov 7, 2023
@CKEditorBot CKEditorBot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:expired This issue was closed due to lack of feedback. status:discussion status:stale type:docs This issue reports a task related to documentation (e.g. an idea for a guide).
Projects
None yet
Development

No branches or pull requests

4 participants