-
Notifications
You must be signed in to change notification settings - Fork 127
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
Decorators for generators? #24
Comments
FWIW, here's my use case: function checkCallable(desc) {
const original = desc.value
desc.value = function (f) {
assertCallable(f, 'f')
return original.apply(this, arguments)
}
}
function wrap(desc) {
const original = desc.value
desc.value = function () {
return new Wrapper(original.apply(this, arguments))
}
}
class Wrapper {
// ...
@checkCallable @wrap *map(f) {
let index = 0
for (const entry of this) {
yield f(entry, index++)
}
}
@checkCallable @wrap *filter(f) {
let index = 0
for (const entry of self) {
if (f(entry, index++)) {
yield entry
}
}
}
// ...
} |
👍 I'm surprised this didn't work already, as generators seem to work just like normal functions for everything else (like static class methods, for example). |
We're making an app using KOA, and it was exciting to use decorators to give all of our methods an |
Running into the same issue, trying to decorate generator functions in a Koa app for routing purposes. From another thread, I see this is an issue of ambiguous grammar, but that thread seems to suggest the underlying issue is resolved: https://phabricator.babeljs.io/T2014. Is there a way to get this to work now? |
@galenwarren You are correct (#34). I think the only outstanding part remaining is a PR. |
This is the one part I was surprised didn't exist. Every other possibility I can think of is covered with this proposal, but I think generators might have been overlooked.
I have already come across a problem where I needed this functionality, and I ran into issues.
Is there any reason generators shouldn't be decorated?
The text was updated successfully, but these errors were encountered: