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

[GLIMMER] Ensure objects with .forEach can be iterated. #13904

Merged
merged 1 commit into from
Jul 26, 2016

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Jul 26, 2016

This was supported (though untested) in HTMLBars. Added some tests and implemented in Glimmer.

@@ -175,6 +175,12 @@ class Iterable {
return new EmberArrayIterator(iterable, keyFor);
} else if (Array.isArray(iterable)) {
return iterable.length > 0 ? new ArrayIterator(iterable, keyFor) : EMPTY_ITERATOR;
} else if (iterable.forEach !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to test for typeof iterable.forEach === "function"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure, but that seems fine too. I will change it.

iterable.forEach(function(item) {
array.push(item);
});
return array.length > 0 ? new ArrayIterator(array, keyFor) : EMPTY_ITERATOR;
} else if (isEachIn(ref)) {
Copy link
Member

@chancancode chancancode Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEachIn probably needs to be moved up – if you do {{#each-in someArray ...}} for some reason, it should do what you asked for instead of looping through the array. It's largely unrelated to what you are doing here because even if you move it above your branch it will still be a problem, but we should remember to fix it and add a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll follow up with that in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue rwjblue merged commit 8a9c832 into emberjs:master Jul 26, 2016
@rwjblue rwjblue deleted the enable-for-each-objects branch July 26, 2016 21:14
@vvscode
Copy link
Contributor

vvscode commented Jul 27, 2016

@rwjblue @chancancode #13915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants