-
-
Notifications
You must be signed in to change notification settings - Fork 238
fix: enumerate Promises (e.g. in for & tablerow) #237
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
Conversation
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.
src/builtin/tags/for.ts
Outdated
@@ -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)) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?)
Great job! @all-contributors please add @tejasmanohar for code. |
I've put up a pull request to add @tejasmanohar! 🎉 |
## [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))
🎉 This PR is included in version 9.14.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.