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

Make collection iterable using for of loops #1830

Merged
merged 1 commit into from Apr 27, 2018

Conversation

fl0w
Copy link
Collaborator

@fl0w fl0w commented Apr 27, 2018

Introduction

Make collections iterable using for of loops.

const models = await bookshelf.model('Model').fetchAll()
// previously
for (const model of models.models) {}

// now
for (const model of models) {}

Motivation

It's nice to be able to use default ECMA functionality when they're non-breaking.

Proposed solution

Define CollectionBase.prototype[Symbol.iterator] and yield to this.models (which always defaults to an array)

Current PR Issues

None that I am aware of

Alternatives considered

None that I am aware of

@fl0w fl0w changed the title make collection iterable using for of loops Make collection iterable using for of loops Apr 27, 2018
@fl0w
Copy link
Collaborator Author

fl0w commented Apr 27, 2018

My god, I completely missed #1817, still think my solution is cleaner. Apologies :)

@ricardograca ricardograca added this to To Do in Version 0.14.0 via automation Apr 27, 2018
Copy link
Member

@ricardograca ricardograca left a comment

Choose a reason for hiding this comment

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

This needs to have accompanying tests to ensure the correct behavior.

@fl0w
Copy link
Collaborator Author

fl0w commented Apr 27, 2018

Added a simple test, if it's not enough pointers are appreciated and I'll add tests accordantly.

@ricardograca ricardograca merged commit cbf9675 into bookshelf:master Apr 27, 2018
Version 0.14.0 automation moved this from To Do to Done Apr 27, 2018
@fl0w fl0w deleted the collection-iterator branch April 29, 2018 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants