-
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
decorator for variables #32
Comments
Isn't this ambiguous when you have more than one declarator? |
Hey @sebmck, |
@decorator
let somethingWorkLikeClass = aFunctionThatReturnsObject(), foo = "bar"; |
Thanks @sebmck, |
@yongxu What does this provide that is not covered by doing
though? |
@loganfsmyth Yes, that is actually what I did when I found out decorator doesn't work on variables. |
Allowing decorators on assignment (and/or @memoize({ttl: 30})
export function getStuff(id) {
...
} Instead of: export const getStuff = memoize({ttl: 30})(function getStuff(id) {
...
}); |
There's also the unfortunate "function naming" thing. The only way to have named functions with "decorators" is the following right now: export const getStuff = memoize({ ttl: 30 })(function getStuff(id) {}); Compared to (given @memoize({ ttl: 30 })
export const getStuff = () => {} |
Yes the Class decorators have been used by the React community extensively in the form of so-called Higher Order Components. Personally I have found Higher Order Components to promote a simpler coding style then mixins with more obvious boundaries between objects. I sincerely hope we can bring a syntax to encourage this coding style back into es7 through export decorators like @jkrems example. |
Another use case . With react stateless component decorator doesn't work . same issue
|
I think that this is pretty much the same as for free function decorators. Hoisting might be a problem here. And, in accordance to your overall stance towards free function decorators, this should be a won't fix and should be closed (for future review of course, once we get rid of that annoying hoisting feature) in order to get this going again. |
|
Hey there,
I tried today using babel and realize it doesn't work:
Babel will raise SyntexError: Leading decorator must be attached to a class declaration.
I think it would be very useful to have decorators work on variable, especially when work with some other new features like Object.observe() and decorate class returned by a factory function.
The text was updated successfully, but these errors were encountered: