-
Notifications
You must be signed in to change notification settings - Fork 107
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
diferenciate get and set and decorator #256
Comments
I can see that the new behavior would be a regression for you. Can you give a little more context about why this situation comes up? |
Into new README.md we can read:
As a result, our problem is resolved with the the class C {
@wrap(f) set prop(v) { }
} is roughly equivalent to the following: class C {
set prop(v) { }
}
const descr = Object.getOwnPropertyDescriptor(C.prototype, 'prop');
descr.set = f(C.prototype.method);
Object.defineProperty(C.prototype, 'prop', descr); But, class C {
@register(f) set prop(v) { }
} is roughly equivalent to class C {
set prop(v) { }
}
f(C, "prop"); In this case, we don't kwon if the decorator intentionally write over the setter or over the getter. If we want to decorate the getter / setter pair with class C {
@register(f) set prop(v) { }
@register(f) get prop() { }
} is roughly equivalent to class C {
set prop(v) { }
get prop() {}
}
f(C, "prop");
f(C, "prop");
Some generic decorators can be applied with full meaning to the getter and/or setter methods. It is the programmer who decides whether to apply this decorator on both or on only one of them. For example: Other generic decorators only make sense about the getter method or about the setter method. Finally, other generic decoratos has sense about the property and need the pair getter/setter. For example, Therefore, we have all the possible cases and combinations and they all make sense. |
It seems reasonable that any decorator applied to a getter or a setter both has access to the coalesced pair, and knows on which of the two it is applied. |
That is definitely a possible design, but coalescing was a rather complicated part of the specification, and the use cases were unclear. In the January 2019 TC39 meeting, there was a general concern expressed that the decorators proposal was too big and complicated, so eliminating this aspect was an attempt to respond to that feedback. Note that a coalesced getter/setter in a class is just a concept that doesn't exist before this proposal. This issue is useful to understand some cases; any more times when you all can think of this coming up would be useful. |
If that's the case, then why make it so in this proposal? It's fairly clear that applying a decorator to the handlers of a property separately has merit. |
I'd be interested to hear how the new decorators proposal works for this aspect of these use cases. |
In particular, the new proposal lets the decorator know, in the context object, whether it was placed over a getter or setter. I think that should resolve this issue, right? |
For the most part, if I'm understanding the current README.md, this should work. There are some curiosities though. In the comments about
I'm a little perplexed by this. If the original class definition looks like so: class Base {
#a = "some constant";
get a() { return this.#a; }
set a(v) { this.#a = v; }
}
class Ex extends Base {
@inherited a = 2;
} According to the new proposal, |
We are founding a very special and curious case with getter/setter decorators. Let's suppose we have a general decorator for methods (ie a
@trace
). We want to be able to apply this decorator only over the getter or the setter. Nevertheless, we don't kwon if the user programmer put our decorator over the setter or getter.We have not any manner to find out where is placed the decorator, over the
set
or over theget
, and as a result there is not mean to apply rightly the decorator.Is it possible to get a indicator or another flag to kwon where the decorator is placed, whether over the getter or over the setter? The feature would be very useful in some cases.
The text was updated successfully, but these errors were encountered: