-
Notifications
You must be signed in to change notification settings - Fork 106
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
Static decorators: some questions / concerns based on MobX #267
Comments
Not in this proposal. I wonder if we should allow this purely as a syntactic affordance, but I don't think we could allow these to be actual objects without compromising the static analyzability goals. Would something
Yes, everything is well-defined with respect to that.
A bunch of people have asked about this (e.g., #260); I think we could make it "just work", and let
Yes
To some extent-- you can make I'm wondering if we could make some facility for conditionals within
Right, it would just apply to the getter. Coalescing was a major source of complexity previously, and it seems unnecessary for most (but not all, see #256) use cases. I've been thinking that we could make a special built-in decorator to trigger coalescing for the cases where it's needed. |
While I don't think that it is needed in the initial implementation, something like this would be statically analyzable: decorator @action {
@wrap(f => action(f)) // Perfect!
@initializer((value, key) => {
this[key] = action(value)
})
decorator @bound {
// @action.bound decorator implementation
}
} PS. Don't forget to always wrap decorators in backticks, or you'll ping thousands of people 😛 |
Imho, and it has the benefit of better tree-shakeable code. It will have quite some impact on the community, docs etc though.
Yes that would be perfect, it is also the reason why the current TypeScript experimental decorators work better for fields in MobX case, then Babel legacy implementation.
I wouldn't go down that road to quickly. In worst case, I think we could introduce separate api's for these cases, although it is not ideal.
If |
I can see how that would be helpful, and how it's useful in experimental decorators, but at the same time, I would prefer to ask people to get it through reflection at first. The reason is because it would cause performance overhead to materialize this descriptor, and most decorators don't need it. |
@littledan that makes perfect sense! My first worry was that it wouldn't be available through reflection either. If it is, then there is no limitation. |
(Note, the descriptor is only available for public class elements, not private.) |
Thanks for the feedback; we've moved on to another proposal based on all of your feedback; see #310 and the README. |
I've checked whether the most important decorator's can be expressed in the static proposal, which raises a few questions, see the pseudo code below for more explanation:
@action x =
and@action.bound x =
,@observable x = 3
and@observable.ref = {}
@register
happens always before@initialize
(if I understand the proposal correctly the answer is yes)this
as property target if there is no initializer expression in play? In other words, will@initializer
be invoked withundefined
forclass X { @decorator y }
?@observer
andobserver
can still be given different meaning? (if I understand the proposal correctly the answer is yes)@action y() {}
and@action y = () => {}
work in MobX@computed get() x {} set() x{}
no longer applies@computed
to the setter as is it did before?Pseudo implementation of MobX's decorators using this proposal, giving this some context
I realize this is quite an unstructured rambling, so if there are some things unclear, I'll happily open a separate issue to discuss an individual problem:
Despite these questions, and it being probably impossible to maintain literally the same MobX api (seems quite a re-design is needed with this proposal), I do like the way how decorators are written :) it all does seem more explicit and intuitive.
The text was updated successfully, but these errors were encountered: