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

fix: enumerate Promises (e.g. in for & tablerow) #237

Merged
merged 5 commits into from
Jun 28, 2020

Conversation

tejasmanohar
Copy link
Contributor

@tejasmanohar tejasmanohar commented Jun 27, 2020

Previously, a Promise of an array was not being enumerated in
{% for %}, for example. This is unexpected since the library
handles promises elsewhere (e.g. if you {% assign x = promiseArray %}
and then {% for v in x %}, it worked just fine.

This PR makes Promises of arrays handled by changing toEnumerable
to handle then-ables. This affects other iterators, too, e.g. tablerow,
so I put in a test for that as well.

Previously, a Promise of an array was not being enumerated in
{% for %}, for example. This is misleading since the library
handles promises elsewhere (e.g. if you {% assign x = promiseArray %}
and then {% for v in x %}, it worked just fine.

This PR makes Promises of arrays handled by changing toEnumerable
to handle then-ables. This affects other iterators, too, e.g. tablerow,
so I put in a test for that as well.
@@ -36,7 +36,7 @@ export default {
},
render: function * (ctx: Context, emitter: Emitter) {
const r = this.liquid.renderer
let collection = toEnumerable(evalToken(this.collection, ctx))
let collection = yield toEnumerable(evalToken(this.collection, ctx))
Copy link
Owner

@harttle harttle Jun 27, 2020

Choose a reason for hiding this comment

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

Can we yield the value (which may be a thenable) instead of the toEmumerable(), that'll keep toEnumerable clean and not aware of promises or/and the generator trick. Like:

let collection = toEnumerable(yield evalToken(this.collection, ctx))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah sure, one sec. not that familiar with generators tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! How's that? @harttle

Copy link
Contributor Author

@tejasmanohar tejasmanohar Jun 27, 2020

Choose a reason for hiding this comment

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

View final diff, I have some dummy commits (you can squash / merge via GitHub?)

@harttle harttle merged commit 941dd66 into harttle:master Jun 28, 2020
@harttle
Copy link
Owner

harttle commented Jun 28, 2020

Great job! @all-contributors please add @tejasmanohar for code.

@allcontributors
Copy link
Contributor

@harttle

I've put up a pull request to add @tejasmanohar! 🎉

harttle pushed a commit that referenced this pull request Jul 8, 2020
## [9.14.1](v9.14.0...v9.14.1) (2020-07-08)

### Bug Fixes

* enumerate Promises (e.g. in for & tablerow) ([#237](#237)) ([941dd66](941dd66))
@harttle
Copy link
Owner

harttle commented Jul 8, 2020

🎉 This PR is included in version 9.14.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants